经过一段时间的问题搜索我有我没有遇到任何解决方案。所以我在这里。
一些背景,我想自动化注册,确认,并加入了“现场课堂”为特定平台。
要做到这一点,你必须每10分钟5分钟车窗口,您可以注册,然后确认,然后等待X的时间,然后加入居住类。
但是,这仅仅是第一部分,在这里我要报名。这是我做过什么用流利的等待:
public void joinPrivateClass() {
System.out.println("Starting join private class");
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(Duration.ofSeconds(480))
.pollingEvery(Duration.ofSeconds(5))
.ignoring(NoSuchElementException.class);
WebElement signUp = wait.until(new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
WebElement signUpButton = driver.findElement(By.xpath("//*[@id=\"live-class-322102\"]/div[1]/div/div/button"));
if(signUpButton.isDisplayed()){
System.out.println("button is displayed");
} else {
System.out.println("button is not displayed yet");
}
return signUpButton;
}
}); signUp.click();
}
我的问题是,页面加载后,而fluentwait“作品”我希望有一个“按钮不会显示”每5秒,直到它再被点击。但同时该按钮,显示或不,我没有得到任何消息,既不是“不显示按钮”,也不是“显示按钮”,所以我会假设的东西是在“wait.until”失败
有些事情说,我不是一个程序员,如果我做错了什么很抱歉,
另外,在我的IDE(的IntelliJ)它标志着我的代码,这部分的“驱动器”
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
在“紫色”,而这种“驱动程序”:
public WebElement apply(WebDriver driver)
灰色,如果它有什么关系!感谢您的宝贵帮助
你wait
是建立与ignoring(NoSuchElementException.class)
。所以只要按钮不存在,您wait.until(...)
将只是默默的守在findElement(...)
线失败 - 它永远不会使它的println(...)
。
从你的等待中取出ignoring(...)
,你的身体wait.until(...)
更改为类似:
WebElement signUpButton;
try {
signUpButton = driver.findElement(By.xpath("//*[@id=\"live-class-322102\"]/div[1]/div/div/button"));
System.out.println("button is displayed");
} catch(NoSuchElementException ignored) {
System.out.println("button is not displayed yet");
}
return signUpButton;