Monday, December 8, 2014

Webdriver isDisplayed()

Webdriver isDisplayed()

isDisplayed(): Selenium Webdriver’s isDisplayed() method is a boolean method i.e. it returns true or false. This method determines if an element is currently being displayed on a web page or not.

isDisplayed() method’s API syntax:
boolean isDisplayed()

Example of isDisplayed()
Below code determines if Google Search button is displayed on a web page and returns true if it is displayed:

public class isDisplayed {
 public static void main (String[] args){
WebDriver driver = new FirefoxDriver();
driver.get(“http://www.google.com”);
WebElement searchButton =
driver.findElement(By.name(“btnK”));
System.out.println(searchButton.isDisplayed());
}
}
[Source of above example: Selenium WebDriver Practical Guide by Satya Avasarala]

More on isDisplayed() and its examples below:

1. How does Selenium WebDriver's isDisplayed() method work. [Link]
2. How to check if an element is visible with WebDriver. [Link]
3. Selenium WebDriver - Using isDisplayed() method for verifying the presence of elements. [Link]
4. how to verify element present or visible in selenium 2. [Link]
5. Selenium Webdriver isDisplayed() method? [Link]
6. Selenium Webdriver - using isDisplayed() in If statement is not working. [Link]
7. Can someone provide a detailed description of how the Selenium WebDriver isDisplayed() method works? [Link]
8. Using isDisplayed( ) to verify whether an element is available. [Link]
9. Check Visibility of Web Elements Using Various Types WebDriver Commands. [Link]