我在 WebDriver
上执行了一个操作(比如说,我点击了一个按钮),结果是一个文本将显示在页面上。
我们不知道文本的定位器元素,但我们知道将显示什么文本。
请建议一种等待文本显示的方法。
我遇到过WebDriverWait
,但是它需要WebElement
来等待文本。
最佳答案
进行基于 xpath 文本的搜索。它允许您根据文本查找元素
// with * we are doing tag indepenedent search. If you know the tag, say it's a `div`, then //div[contains(text(),'Text To find')] can be done
By byXpath = By.xpath("//*[contains(text(),'Text To find')]");
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(byXpath));
关于java - WebDriver - 如何让 webdriver 等到显示文本(不使用定位器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30190193/