Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between isElementPresent and isVisible in Selenium RC

What is the difference between element isElementPresent and isVisible in Selenium RC. I get true for

selenium.isElementPresent() and selenium.isVisible()

If I get false for selenium.isElementPresent() I get Exception on selenium.isVisible()

like image 747
Harshavardhan Konakanchi Avatar asked Apr 19 '12 07:04

Harshavardhan Konakanchi


People also ask

What is difference between isDisplayed and isPresent?

isDisplayed resolves to whether the element is visible or not, but throws an exception if it is not in the DOM. isPresent resolves to whether it is there in the DOM or not, regardless of whether it is actually visible or not. It doesn't throw an exception.

What is the difference between presence of element and visibility of element?

isElementPresent() - This method basically tests if the element we are looking for is present somewhere on the page. isVisible() - looks for display: none style tag - this might throw a null pointer if we aren't careful...

What is the difference between isDisplayed and isEnabled in WebDriver?

isDisplayed() is capable to check for the presence of all kinds of web elements available. isEnabled() is the method used to verify if the web element is enabled or disabled within the webpage. isEnabled() is primarily used with buttons. isSelected() is the method used to verify if the web element is selected or not.

Is displayed and is visible difference?

isVisible is method of old Selenium RC and isDisplayed is method of Selenium 2. An element can be rendered invisible by setting the CSS "visibility" property to "hidden", or the "display" property to "none", either for the element itself or one if it's ancestors. This method will fail if the element is not present.


2 Answers

isElementPresent() - This method basically tests if the element we are looking for is present somewhere on the page.

isVisible() - looks for display: none style tag - this might throw a null pointer if we aren't careful...thus to see if an element is visible first check if the element is present using isElementPresent() method. Then try checking if the element is visible!

Observe that isElementPresent() won't mind even if our element is not visible.

For ex: lets say the below is the html code for a component on my test application:

now if you test the above component with

selenium.isElementPresent("testinput") - returns true!
selenium.isVisible("testinput") - returns false!
like image 94
Sachin Mhetre Avatar answered Nov 02 '22 03:11

Sachin Mhetre


How about reading the documentation?

boolean isElementPresent(java.lang.String locator)

Verifies that the specified element is somewhere on the page.

boolean isVisible(java.lang.String locator)

Determines if the specified element is visible. An element can be rendered invisible by setting the CSS "visibility" property to "hidden", or the "display" property to "none", either for the element itself or one if its ancestors. This method will fail if the element is not present.

like image 31
JB Nizet Avatar answered Nov 02 '22 03:11

JB Nizet