- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How does Selenium WebDriver's isDisplayed() method work?
We can work with isDisplayed() method in Selenium webdriver. This method checks if a webelement is visible on the page. If it is visible, then the method returns a true value, else it returns false.
First of all, we have to identify the element with any of the locators like id, class, name, xpath or css and then apply isDisplayed() method on it.
Syntax
boolean s= driver.findElement(By.id("txt-bx")).isDisplayed();
Let us check if the element About Careers at Tutorials Point is displayed on the page. Since it is available it shall return a true value.
Example
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class VisibleElement{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver","C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.get("https://www.tutorialspoint.com/about/about_careers.htm"); // identify element WebElement p=driver.findElement(By.xpath("//h1")); //isDisplayed() to check if element visible boolean s= p.isDisplayed(); System.out.println("The return value: " + s); driver.close(); } }
Output
- Related Articles
- How does the Selenium WebDriver work?
- How does Selenium RC work?
- How does selenium webdriver upload files to the browser?
- How does Selenium Webdriver handle SSL certificate in Firefox?
- How does Selenium Webdriver handle SSL certificate in Chrome?
- How does Selenium Webdriver handle the SSL certificate in Safari?
- How does Selenium Webdriver handle the SSL certificate in Edge?
- How does jQuery replaceWith() method work?
- Why does the Selenium WebDriver have an edge over Selenium RC?
- How does Python's Matplotlib.pyplot.quiver exactly work?
- How does jQuery.filter() method work in jQuery?
- How does jQuery.find() method work in jQuery?
- How does jQuery.eq() method work in jQuery?
- How does jQuery.map() method work in jQuery?
- How does jQuery.slice() method work in jQuery?

Advertisements