- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 to verify if an element is displayed on screen in Selenium?
We can verify the visibility of web elements like edit box, checkbox, radio buttons and so on with the help of method listed bels −
isDisplayed()
This method checks if a webelement is present on the screen.
Syntax −
Boolean result = driver.findElement(By.xpath("//span[text()=’Coding Ground’]")).isDispayed();
isSelected()
This method checks the status of the radio button, check box and options in the static dropdown.
Syntax −
Boolean btnresult = driver.findElement(By.xpath("//xpath[contains(@class,’gsc-search-button’)]")).isSelected();
isEnabled()
Syntax −
Boolean btnresult = driver.findElement(By.xpath("//xpath[contains(@class,’gsc-search-button’)]")).isEnabled();
This method if an element is enabled or not.
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 ElementStatus{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://www.tutorialspoint.com/tutor_connect/index.php"; // to verify if a static dropdown is selected with option isSelected() boolean drpdwnStatus = driver.findElement(By.xpath("//select[@name=’selType’]")) .isSelected(); // to verify if an element is present on page with isDisplayed() boolean editStatus = driver.findElement(By.xpath("//input[@id=’txtSearchText’]")) .isDisplayed(); // to verify if a button is enabled with isEnabled() boolean butnStatus = driver.findElement(By.xpath("//input[@id=’searchSubmit’]")) .isEnabled(); System.out.println("The button status is " + butnStatus); System.out.println ("The dropdown selected status is" + drpdwnStatus); System.out.println("The edit box display status is " + editStatus); driver.close(); } }
- Related Articles
- How to check if an image is displayed on page using Selenium?
- How to verify an attribute is present in an element using Selenium WebDriver?
- How do I verify that an element does not exist in Selenium 2?
- How to verify color of a web element in Selenium Webdriver?
- How to perform mouseover action on an element in Selenium?
- How to perform double click on an element in Selenium?
- How to perform double click on an element in Selenium with python?
- How to perform right click on an element in Selenium with python?
- How to perform right click on an element with Actions in Selenium?
- Test if an element is focused using Selenium Webdriver.
- How to wait until an element is present in Selenium?
- How to verify the color and background color of a web element in Selenium?
- Scroll element to the middle of the screen with Selenium
- How to perform releasing a mouse on an element in Selenium with python?
- How to verify specific text exists within an attribute in Selenium IDE?

Advertisements