jeudi 1 décembre 2016

Selenium WebDriver : How to make sure element availability on Web Page?

I had gone through many google answers for how to make sure element availability before we do action on any web element to avoid "NoSuchElementException" exception.

  1. WebDriver driver = new FirefoxDriver();
  2. driver.findElement(By.id("userid")).sendKeys("XUser");

Here line #2 will throw ""NoSuchElementException" if the element does not available on page.

I just want to avoid this Exception to be thrown.

There are many methods available to check this in WebDriver.

  1. isDisplayed()
  2. isEnabled()
  3. driver.findElements(By.id("userid")).size() != 0
  4. driver.findElement(By.id("userid")).size() != null
  5. driver.getPageSource().contains("userid")

Which is best one in the above methods to make sure element availability? Why?

Is there any other methods available apart from these?

Thanks in Advance. Thank you for your valuable time.

Aucun commentaire:

Enregistrer un commentaire