Selenium webdriver selenium 3.x.x中fluent wait.until()方法的替代解决方案是什么?
selenium 3.x.x中fluent wait.until()方法的替代解决方案是什么 它为util方法提供了一些功能参考Selenium webdriver selenium 3.x.x中fluent wait.until()方法的替代解决方案是什么?,selenium-webdriver,java-8,functional-interface,Selenium Webdriver,Java 8,Functional Interface,selenium 3.x.x中fluent wait.until()方法的替代解决方案是什么 它为util方法提供了一些功能参考 请指导。您可以将流畅的等待与显式等待集成在一起,如下所示 /* * wait until expected element is visible */ public boolean waitForElement(WebDriver driver, By expectedElement) { boolean isFound = true; tr
请指导。您可以将流畅的等待与显式等待集成在一起,如下所示
/*
* wait until expected element is visible
*/
public boolean waitForElement(WebDriver driver, By expectedElement) {
boolean isFound = true;
try {
WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds , 300);
wait.pollingEvery(2, TimeUnit.SECONDS);
wait.until(ExpectedConditions.visibilityOfElementLocated(expectedElement));
makeWait(1);
} catch (Exception e) {
//System.out.println(e.getMessage());
isFound = false;
}
return isFound;
}
高级Web驱动程序等待 创建我们自己的自定义等待或高级WebDriver等待。请参阅此链接
publicstaticvoidmain(String[]args)抛出InterruptedException{
WebDriver=newfirefoxdriver();
驱动程序。获取(“http://toolsqa.wpengine.com/automation-practice-switch-windows/");
FluentWait=新FluentWait(驱动程序);
wait.pollingEvery(250,时间单位为毫秒);
wait.withTimeout(2,TimeUnit.SECONDS);
函数=新函数()
{
公共布尔应用(WebDriver arg0){
WebElement=arg0.findElement(By.id(“colorVar”);
字符串颜色=element.getAttribute(“颜色”);
System.out.println(“按钮为“+颜色时的颜色”);
如果(颜色等于(“红色”))
{
返回true;
}
返回false;
}
};
等到(函数);
}
你的问题不清楚。为什么需要WebDriverWait或FluentWait的替代品?它们都存在于Selenium 3中,因为等待,直到Selenium 3不再起作用。所以我正在寻找另一种方法来处理until方法。
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("http://toolsqa.wpengine.com/automation-practice-switch-windows/");
FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver);
wait.pollingEvery(250, TimeUnit.MILLISECONDS);
wait.withTimeout(2, TimeUnit.SECONDS);
Function<WebDriver, Boolean> function = new Function<WebDriver, Boolean>()
{
public Boolean apply(WebDriver arg0) {
WebElement element = arg0.findElement(By.id("colorVar"));
String color = element.getAttribute("color");
System.out.println("The color if the button is " + color);
if(color.equals("red"))
{
return true;
}
return false;
}
};
wait.until(function);
}