Java 如何等待属性具有不同的值?
当我们没有在屏幕上等待时Java 如何等待属性具有不同的值?,java,selenium-webdriver,webdriver,webdriverwait,expected-condition,Java,Selenium Webdriver,Webdriver,Webdriverwait,Expected Condition,当我们没有在屏幕上等待时 <div id="divWait" style="cursor: wait; position: absolute; left: 0%; top: 0%; background: transparent; padding: 3px; width: 100%; height: 100%; display: none;"> 但它不起作用我们可以等到显示属性不存在 WebDriverWait wait = new WebDriverWait(driver,60)
<div id="divWait" style="cursor: wait; position: absolute; left: 0%; top: 0%; background: transparent; padding: 3px; width: 100%; height: 100%; display: none;">
但它不起作用我们可以等到
显示
属性不存在
WebDriverWait wait = new WebDriverWait(driver,60);
wait.until(new ExpectedCondition<Boolean>() {
boolean isAttributeNotPresent= false;
public Boolean apply(WebDriver driver)
{
WebElement button = driver.findElement(By.id("divWait"));
if(button.isDisplayed()
{
try{
button.getAttribute("display");
}
catch(Exception e)
{
isAttributeNotPresent= true;
return isAttributeNotPresent;
}}
}});
WebDriverWait wait=newwebdriverwait(驱动程序,60);
等待.until(新的ExpectedCondition(){
布尔值isAttributeNotPresent=false;
公共布尔应用(WebDriver驱动程序)
{
WebElement按钮=driver.findElement(By.id(“divWait”);
if(button.isDisplayed()
{
试一试{
getAttribute(“显示”);
}
捕获(例外e)
{
isAttributeNotPresent=真;
返回isAttributeNotPresent;
}}
}});
注意:忽略语法错误,因为我正在从移动键盘键入内容似乎您已接近。要等待属性显示:无从样式属性中删除,而不是预期的条件,如
invisibilityOfElementLocated()
您必须诱导WebDriverWait以实现元素定位()的可见性,并且您可以使用以下任一选项:
:css选择器
WebElement element = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div#divWait")));
:xpath
WebElement element = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='divWait']")));
WebElement element = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div#divWait")));
WebElement element = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='divWait']")));