The isDisplayed() method

The isDisplayed action verifies whether an element is displayed on the web page and can be executed on all the WebElements. The API syntax for the isDisplayed() method is as follows:

boolean isDisplayed()

The preceding method returns a Boolean value specifying whether the target element is displayed on the web page. The following is the code to verify whether the Search box is displayed, which obviously should return true in this case:

@Testpublic void elementStateExample() {    WebElement searchBox = driver.findElement(By.name("q"));    System.out.println("Search box is displayed: "            + searchBox.isDisplayed());}

The preceding code uses the isDisplayed() method to determine whether the element is displayed on a web page. ...

Get Selenium WebDriver 3 Practical Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.