
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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(); } }
Advertisements