Thursday 9 February 2017

SELENIUM: How to check whether element is present or not in web page


How to check whether element is present or not in web page:



There are many ways to check  the web element is present in web page or not.
Among that i m giving you two simple ways.

First Way: Using isEmpty()
If this method returns "true" means element Is not present on page and "false" means element Is present on page.
Syntax: public boolean isEmpty() ;

Example:   boolean ele_present= driver.findElements(By.id("Email")).isEmpty(); 



Second  Way: Using size()
If the method returns "false" means element Is not present on page and "true" means element Is present on page.

syntax: public boolean size()

Example:
 boolean ele_present = driver.findElements( By.id("Email") ).size() != 0;
 

1 comment: