等待直到文本字段中的文本存在
在webdriver中,如何要求webdriver等到文本字段中存在文本。
实际上我有一个kendo文本字段,其值来自数据库,需要一些时间来加载。 一旦它加载我可以继续进行。
请帮忙
您可以使用WebDriverWait。 从docs示例:
(new WebDriverWait(driver, 10)).until(new ExpectedCondition() { public Boolean apply(WebDriver d) { return d.findElement(...).getText().length() != 0; } });
您可以使用WebDriverWait。 从docs示例:
上面的ans使用.getTex()这不是从输入字段返回文本
使用.getAttribute(“value”)而不是getText()
(new WebDriverWait(driver, 10)).until(new ExpectedCondition() { public Boolean apply(WebDriver d) { return d.findElement(...).getAttribute("value").length() != 0; } });
测试100%工作希望这将有所帮助
您可以使用一种简单的方法,在该方法中,您需要传递文本将要来的驱动程序对象webelement以及将要来的文本。
public static void waitForTextToAppear(WebDriver newDriver, String textToAppear, WebElement element) { WebDriverWait wait = new WebDriverWait(newDriver,30); wait.until(ExpectedConditions.textToBePresentInElement(element, textToAppear)); }
一个工作和使用lambdafunction的衬垫。
wait.until((ExpectedCondition) driver -> driver.findElement(By.id("elementId")).getAttribute("value").length() != 0);
使用WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait)和ExpectedCondition(org.openqa.selenium.support.ui.ExpectedConditions)对象
WebDriverWait wait = new WebDriverWait(driver, 30); wait.until(ExpectedConditions.textToBePresentInElement(By.id("element_id"), "The Text"));
这是我将文本发送到输入的解决方案:
public void sendKeysToElement(WebDriver driver, WebElement webElement, String text) { WebDriverWait wait = new WebDriverWait(driver, Configuration.standardWaitTime); try { wait.until(ExpectedConditions.and( ExpectedConditions.not(ExpectedConditions.attributeToBeNotEmpty(webElement, "value")), ExpectedConditions.elementToBeClickable(webElement))); webElement.sendKeys(text); wait.until(ExpectedConditions.textToBePresentInElementValue(webElement, text)); activeElementFocusChange(driver); } catch (Exception e) { Configuration.printStackTraceException(e); } } WebElement nameInput = driver.findElement(By.id("name")); sendKeysToElement(driver, nameInput, "some text");
- JavaFX将文本附加到TextArea会抛出exception
- JLabel或JTable单元格上的ActionListener
- Spring引导Hibernate错误java.lang.NoSuchMethodError:javax.persistence.JoinColumn.foreignKey()Ljavax / persistence / ForeignKey;
- 为什么javac抱怨与类的类型参数无关的generics?
- 从HTMLDocument获取所有html作为String
- 如何处理url中的特殊字符作为参数值?
- 所有可能的n组合
- Java中两个图像之间的碰撞检测
- Intellij社区不能为Maven使用http代理