【问题标题】:How to wait till an attribute has a different value?如何等到属性具有不同的值?
【发布时间】:2020-05-05 03:36:03
【问题描述】:

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

<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%;">

我添加的sn-p:

WebDriverWait w =new WebDriverWait(driver,10);
w.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("div//[@id='divWait']").getAttr‌ibute("disabled")));

但是没用

【问题讨论】:

  • 等待属性更改或等待属性删除,因为“显示”被删除
  • 我知道,它的代码?
  • 那么问题是什么?
  • “它不起作用”是什么意思?它没有完成预期的任务或引发错误或?使用信息更新您的问题,例如完整的错误消息或对正在发生或未发生的事情的良好描述。如果您发布的 XPath 是您实际使用的,那可能是错误,因为它不是正确的语法。如果您有 ID,则此处不需要 XPath。你到底想做什么?等待等待出现在屏幕上或消失或???请编辑您的问题并添加更多详细信息。

标签: java selenium-webdriver webdriver webdriverwait expected-condition


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    看来你很接近了。要等待属性 display: nonestyle 属性中移除,而不是像 invisibilityOfElementLocated() 那样的 ExpectedConditions,您必须诱导 visibilityOfElementLocated() 的 WebDriverWait,您可以使用以下任一 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']")));
      

    【讨论】:

      猜你喜欢
      • 2021-12-18
      • 2019-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-04
      • 2017-05-17
      相关资源
      最近更新 更多