How to Check If 100% Covered WebElement is Clickable with Selenium

时光总嘲笑我的痴心妄想 提交于 2019-12-01 23:46:43

Have you tried waiting for the invisibility of 4712 before checking the clickability of 4711. 4711 may still register as clickable while 4712 is still visible and that may be causing the issues.

new WebDriverWait(browserInstance.getWebDriver(), 5).until(!ExpectedConditions.elementToBeVisible(By.id("4712")));
new WebDriverWait(browserInstance.getWebDriver(), 5).until(ExpectedConditions.elementToBeClickable(By.id("4711")));

As you mentioned, a Javascript removes the element 4712 it is a bit unclear if the element becomes stale or becomes invisible. So for this step you can use either of the following options:

  • stalenessOf():

    new WebDriverWait(browserInstance.getWebDriver(), 5).until(ExpectedConditions.stalenessOf(driver.findElement(By.id("4712"))));
    
  • invisibilityOfElementLocated():

    new WebDriverWait(browserInstance.getWebDriver(), 5).until(ExpectedConditions.invisibilityOfElementLocated(By.id("4712")));
    
  • not along with visibilityOfElementLocated()

    new WebDriverWait(browserInstance.getWebDriver(), 5).until(ExpectedConditions.not(ExpectedConditions.visibilityOfElementLocated(By.id("4712"))));
    
  • not along with presenceOfElementLocated()

    new WebDriverWait(browserInstance.getWebDriver(), 5).until(ExpectedConditions.not(ExpectedConditions.presenceOfElementLocated(By.id("4712"))));
    

For the next step you want to validate if element 4711 is clickable or not and you can use the following line of code:

new WebDriverWait(browserInstance.getWebDriver(), 5).until(ExpectedConditions.elementToBeClickable(By.id("4711")));

Note: An element's state as enabled=true and displayed=true isn't equivalent to element is interactable i.e. clickable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!