Harshavardhan Konakanchi
Harshavardhan Konakanchi

Reputation: 4294

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()

Upvotes: 10

Views: 27270

Answers (2)

Sachin Mhetre
Sachin Mhetre

Reputation: 4543

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!

Upvotes: 23

JB Nizet
JB Nizet

Reputation: 692023

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.

Upvotes: 12

Related Questions