Java Selenium 3.4如何使用已更改的wait.until
因此,对于Selenium 3.4,我以前使用的Java Selenium 3.4如何使用已更改的wait.until,java,selenium,selenium-webdriver,selenium3,Java,Selenium,Selenium Webdriver,Selenium3,因此,对于Selenium 3.4,我以前使用的wait.until不起作用(被新方法取代)。不过,我似乎无法使新方法起作用 我正在使用 import com.google.common.base.Function; 旧代码: public boolean waitForURLToMatch(String expectedURL, int waitTime){ WebDriverWait wait = new WebDriverWait(driver, waitTime); w
wait.until不起作用(被新方法取代)。不过,我似乎无法使新方法起作用
我正在使用
import com.google.common.base.Function;
旧代码:
public boolean waitForURLToMatch(String expectedURL, int waitTime){
WebDriverWait wait = new WebDriverWait(driver, waitTime);
wait.until(EcpectedConditions.urlMatches(expectedURL));
}
新代码:
public boolean waitForURLToMatch(String expectedURL, int waitTime){
WebDriverWait wait = new WebDriverWait(driver, waitTime);
wait.until(new Function<WebDriver, boolean>){
@Override
public boolean apply(WebDriver driver) {
return driver.getCurrentUrl().equals(expectedURL);
}
}
}
公共布尔waitForURLToMatch(字符串expectedURL,int waitTime){
WebDriverWait wait=新的WebDriverWait(驱动程序,等待时间);
wait.until(新函数){
@凌驾
公共布尔应用(WebDriver驱动程序){
返回driver.getCurrentUrl().equals(expectedURL);
}
}
}
新代码在eclipse中有一个错误:
令牌上出现语法错误,应为InterfaceHeader
你知道我哪里出错了吗?所以在谷歌搜索了很多次之后,我最终发现问题只是语法 这项工作:
public boolean waitForURLToMatch(String expectedURL, int waitTime){
Wait<WebDriver> wait = new WebDriverWait(driver, waitTime);
Function<WebDriver, Boolean> function = new Function<WebDriver, Boolean>() {
public Boolean apply(WebDriver driver) {
String currentURL = driver.getCurrentUrl();
if(currentURL.equals(expectedURL))
{
truefalse = true;
return truefalse;
}
truefalse = false;
return truefalse;
}
};
try{
wait.until(function);
} catch (TimeoutException e){
}
return truefalse;
}
公共布尔waitForURLToMatch(字符串expectedURL,int waitTime){
Wait Wait=新的WebDriverWait(驱动程序,waitTime);
函数=新函数(){
公共布尔应用(WebDriver驱动程序){
字符串currentURL=driver.getCurrentUrl();
if(currentURL.equals(expectedURL))
{
真假=真;
返回truefalse;
}
真假=假;
返回truefalse;
}
};
试一试{
等到(函数);
}捕获(TimeoutException e){
}
返回truefalse;
}
编辑:好的,看来这只是一个类路径冲突,现在一切都正常了,类路径冲突与Selenium一起删除不推荐的直到(谓词)混淆了问题。将检查正则表达式,使用
urlToBe
或urlContains
。另外,如果您没有使用guava库的任何显式函数,则无需更新该函数。。你们提到的错误在最近的一次会议上得到了修正verion@Madhan感谢您的回复,我将如何使用urlToBe或urlContains,until方法已更改,谓词已删除,现在只有until(FunctionUseExpectedConditions
在wait.until()中)
@Madhan-until在3.2中更改,不再接受ExpectedConditions,因此产生了这个问题。这对我来说很有效。有一个小细节。它指的是对象的布尔值,而不是原语的布尔值。