代码之家  ›  专栏  ›  技术社区  ›  Northers

如何等待对象不可单击?

  •  2
  • Northers  · 技术社区  · 8 年前

    我可以轻松检查对象是否可单击:-

    WebDriverWait(driver, 10).until(ec.element_to_be_clickable((By.XPATH, '//*[@id="table-defaults-7"]/div/div/div/div/span/button[2]')))
    

    有没有相反的方法?我的场景是,我有一个带有保存和取消按钮的页面。当我更改页面上的数据时,两个按钮都可单击,但当我单击“保存”时,它们都将不可单击,这是我需要检查的事件,以确保已单击“保存”按钮。

    这可能吗?

    干杯

    2 回复  |  直到 8 年前
        1
  •  2
  •   abybaddi009    8 年前

    我假设你 save 按钮的属性可以是 enabled disabled . 假设在启用和禁用之间切换的属性命名为 status .

    import time
    
    element = driver.find_element(By.XPATH, 'your xpath')
    
    #after clicking the save button
    
    buttonStatus = element.get_property('status')    # should be "enabled"
    timeout = 0
    
    # loop till the status becomes disabled or a timeout
    while buttonStatus != 'disabled' and timeout <= 5:
        buttonStatus = element.get_property('status')
        timeout += 1
        time.sleep(1)                               # sleep for 1 second
    

    请检查 element.is_enabled() 方法并相应更改上述代码。

        2
  •  0
  •   Naveen Kumar R B    8 年前

    尝试否定( not 方法)。

    Java语言 版本:

    new WebDriverWait(driver, 10).until(not(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='table-defaults-7']/div/div/div/div/span/button[2]'"))));
    

    此处链接:

    https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html#not-org.openqa.selenium.support.ui.ExpectedCondition-