Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

isDisplayed() vs isVisible() in Selenium

What is the difference between isDisplayed() and isVisible() methods in Selenium? Both are used to identify whether web element is or is not hidden in web page.

like image 243
MrNolan Avatar asked Dec 20 '15 10:12

MrNolan


People also ask

How to use isdisplayed() method in Selenium WebDriver?

The isDisplayed () method is used to check whether an element is displayed on a web page or not. It returns a boolean value (true) if the target element is displayed otherwise returns false. The syntax for isDisplayed () method in Selenium is as follows: driver.findElement (By.locatorType ("path")).isDisplayed ();

What is isvisible () method in selenium?

Before webdriver we had Selenium RC, which is now long deprecated, the DefaultSelenium class had isVisible () method that: Determines if the specified element is visible.

How to determine the visibility scope of a web element in selenium?

If you use Selenium WebDriver, you are probably aware that there are a number of common ways to loop through and interact with elements on a web page. Among them isDisplayed (), isEnabled (), and isSelected () methods. When a tester needs to ascertain the visibility scope of a web element, they can use these methods.

What is the difference between isdisplayed () and isenabled () in JavaScript?

isDisplayed (): Verifies whether this element displayed or not? isEnabled () : Is the element currently enabled or not ? this will generally return true for everything but for disabled input elements returns false.


2 Answers

Short answer is that isVisible is method of old Selenium RC and isDisplayed is method of Selenium 2.

If you are talking about WebDrivers WebElement, it contains only isDisplayed() method, which by the doc:

Is this element displayed or not? This method avoids the problem of having to parse an element's "style" attribute.

Before webdriver we had Selenium RC, which is now long deprecated, the DefaultSelenium class had isVisible() method that:

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.

reference

like image 84
Erki M. Avatar answered Sep 19 '22 18:09

Erki M.


As explained in this post How does Selenium WebDriver's isDisplayed() method work

WebDriver has its own W3C specification. and the section about determining visibility can give you more information from the spec.

Selenium RC - 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! Refer Difference between isElementPresent and isVisible in Selenium RC

like image 27
parishodak Avatar answered Sep 18 '22 18:09

parishodak