[英]How to wait till an attribute has a different value?
当我们没有在屏幕上等待
<div id="divWait" style="cursor: wait; position: absolute; left: 0%; top: 0%; background: transparent; padding: 3px; width: 100%; height: 100%; display: none;">
但是当等待部分正在进行时,显示部分消失了,所以它变成:
<div id="divWait" style="cursor: wait; position: absolute; left: 0%; top: 0%; background: transparent; padding: 3px; width: 100%; height: 100%;">
我添加的片段:
WebDriverWait w =new WebDriverWait(driver,10);
w.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("div//[@id='divWait']").getAttribute("disabled")));
但它没有用
我们可以等到display
属性不存在
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;
}}
}});
注意:当我从移动键盘输入时忽略语法错误
看来你很接近了。 要等待属性display: none
从style属性而不是ExpectedConditions as invisibilityOfElementLocated()
删除,您必须为visibilityOfElementLocated()
引入WebDriverWait并且您可以使用以下任一定位器策略:
cssSelector
:
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']")));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.