How to verify element is enabled or disabled

During your selenium webdriver test case creation, sometimes you need to verify that your target element is enabled or disabled on web page before performing action on it. Webdriver has built in method isEnabled() to check the element enable status on webpage. 

Element is disabled means it is visible but not editable and element is invisible means it is hidden. 
How to verify element is enabled or disabled in selenium webdriver

isEnabled()
isEnabled() is webdriver method will verify and return true if specified element is enabled. Else it will return false.

Syntax:
boolean FirstName= driver.findElement(By.id("fname")).isEnabled();
System.out.print(FirstName);

isEnabled() method can also be used when there is a condition where we need to take an action based on element status. Please see following example.

1
2
3
4
5
6
7
 //Verify First name text box is enabled or not

  if(FirstName.isEnabled()){
        System.out.print("Text box First name is enabled. ");
  }else{
        System.out.print("Text box First name is disabled.");
  }

isDisplayed()
isDisplayed() is webdriver method will verify and return true if specified element is displayed. Else it will return false.
driver.findElement(By.id("Fname")).isDisplayed();



<-- Previous || Next -->

2 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete