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()
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.
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...
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.
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.
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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With