硒+;Java等待元素可见
我是Selenium&Java新手。我试图完成的是等待一个元素在超时时出现,如果该元素在超时结束之前出现,则继续运行。下面的代码将给出一个硒+;Java等待元素可见,java,selenium,Java,Selenium,我是Selenium&Java新手。我试图完成的是等待一个元素在超时时出现,如果该元素在超时结束之前出现,则继续运行。下面的代码将给出一个TimeoutException,并停止其余代码的运行 WebElement myDynamicElement = (new WebDriverWait(driver, 10)) .until(ExpectedConditions.presenceOfElementLocated(By.id("my_element"))); 请这样做: public
TimeoutException
,并停止其余代码的运行
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(By.id("my_element")));
请这样做:
public boolean isFind(WebElement my_element) {
try{
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(By.id("my_element")));
}
catch(TimeoutException exception) {
return false;
}
return true;
}
谢谢你的帮助,我花了一点时间来摆弄它。这是我想出的解决办法。希望它能帮助下一个人。如果我把事情弄糟了,请告诉我,再次谢谢
try{
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@id='signup_email']")));
}catch (org.openqa.selenium.TimeoutException e){
JOptionPane.showMessageDialog(null, "Login Complete!");
return;
}
您可以使用
ExpectedConditions.visibilityOf
WebDriverWait wait = new WebDriverWait(d, 120);
wait.until(ExpectedConditions.visibilityOf(d.findElement(By.xpath("//input[@id='signup_email']"))));
你试过try/catch吗?是的,但我不知道如何正确使用它。谢谢,这帮我找到了方向!