WebElement Visible and sometimes not Visible

时间:2016-02-03 03:54:29

标签: java selenium-webdriver

The element sometimes become visible and sometimes does not become visible. Also the element is not in the DOM. How to handle this situation using Selenium Webdriver?

1 个答案:

答案 0 :(得分:-1)

1st you can wait for the element to be visible on DOM

WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.visibilityOfElementLocated("YOUR LOcator")));

You can also check if the element is present on DOM or not. Use below code for same

  if (driver.findElements("YOUR LOCATOR").size() != 0) {  
            driver.findElement(YOUR LOCATOR).click();  
            System.out.println("element exists");     
        }  
  else{
           System.out.println("element is not exists");     
      }

Hope it will help you :)

相关问题