isDisplayed()
, isEnable()
and isSelected()
are three different methods to validate three distinct stage of a WebElement.
isDisplayed()
isDisplayed() validates if a certain element is present and displayed. If the element is displayed, then the value returned is true. If not, then the value returned is false. However this method avoids the problem of having to parse an element's style
attribute. Example:
boolean eleDisplayed= driver.findElement(By.xpath("xpath")).isDisplayed();
isEnabled()
isEnabled() validates if an element is enabled. If the element is enabled, it returns a true value. If not, it returns a false value. This will generally return true for everything but disabled input elements. Example:
boolean eleEnabled= driver.findElement(By.xpath("xpath")).isEnabled();
isSelected()
isSelected() method is often used on radio buttons, checkboxes or options in a menu. It is used to determine is an element is selected. If the specified element is selected, the value returned is true. If not, the value returned is false. Example:
boolean eleSelected = driver.findElement(By.xpath("xpath")).isSelected();