Thursday, 10 November 2016

Webdriver/Selenium Difference between methods .isDisplayed() and .isEnabled()?

Hi All,
I have seen so many posts where people asked the differences between .isDisplayed() and .isEnabled() in Selenium/Webdriver automation and found mostly people are still confused.
The methods .isDisplayed() and .isEnabled() have nothing in common.
 Here I am trying to explain the read differences between .isDisplayed() and .isEnabled(). As name itself clearly says .isDisplayed() means is my object are visible or not on my webpage means Am I able to see my element through my eyes.

Method .isDisplayed() :

An element is considered displayed when it is perceptually visible to the human eye.
The element displayed algorithm is a boolean state where true signifies that the element is displayed and false signifies that the element is not displayed.

To compute the state on element:
  • ·         If the attribute hidden is set, return false.
  • ·         If the computed value of the display style property is "none", return false.

<input type="hidden" name="abc" value="10" id="hiddenFiled1" />

Observe the output, since element with id hiddenField1 is hidden from web page, so isDisplayed method return false, whereas isEnabled() method return true.


Refer below link

Try to run with display: block;  and display: none;

Method .isEnabled() :

An element is considered enabled if it's not a form control (button, input, textarea, select or option) or when the user interactions and focus are not blocked with the disabled attribute/property.
Is Element Enabled determines if the referenced element is enabled or not. This operation only makes sense on form controls.

Last name: <input type="text" name="lname" disabled><br>

Last name: <input type="text" name="lname" enabled><br>

Refer below link

Last name: <input type="text" name="lname" disabled><br>

No comments:

Post a Comment

Which one is right ?