-1

当我们在屏幕上没有等待时

<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']").getAttr‌ibute("disabled")));

但它没有用

4

2 回答 2

0

我们可以等待直到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;
}}
}});

注意:当我从移动键盘输入时忽略语法错误

于 2020-01-18T15:08:59.690 回答
0

看来你很接近了。要等待display: nonestyle属性而不是ExpectedConditions中删除属性,因为invisibilityOfElementLocated()您必须诱导WebDriverWait forvisibilityOfElementLocated()并且您可以使用以下任一 Locator Strategies

  • 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']")));
    
于 2020-01-18T23:38:44.430 回答