How to Verify if Element is Enabled or Disabled in Selenium

.
How to Verify if Element is Enabled or Disabled in Selenium Webdriver using Java

isEnabled()
To verify whether the target element (Button, Checkbox, Dropdown, text box, Radio Button, Icons, etc ) is enabled or disabled, use the isEnabled() Method.

Here, Element is disabled, which means the element is present on the webpage but not in editable mode. While working on a real-time project, we have to check whether the element is enabled or not. For example, if some on automating the checkbox, then first they have to check if the checkbox is disabled in Selenium.


Verify element is enabled or disabled in Selenium

What is the isEnabled() Method in Selenium?


 isEnabled() Method 

In Selenium Webdriver isEnabled() method will verify and return a true value if the specified element is enabled. Otherwise, it will return a false value.

Syntax:
The syntax for How to Use isEnabled() with Examples is given below.

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

How to Use isEnabled() with Examples


Selenium Code 

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
 
import org.openqa.selenium.chrome.ChromeDriver;
 
public class FacebookLogin {
 
     public static void main(String[] args) {
           // TODO Auto-generated method stub
           System.setProperty("webdriver.chrome.driver", "C:\\Software\\chromedriver.exe");
           WebDriver driver=new ChromeDriver();
           driver.get("https://www.facebook.com");
          
           //To verify that Element is Enabled
           Boolean nn =driver.findElement(By.xpath("//input[ @type=\"text\"]")).isEnabled();
     if(nn) {
           System.out.println("Yes ! Element is enabled");
     }
     else {
           System.out.println("NO ! Element is disabled");
     }
 
}
}



Hope !!! The above Tutorial on how to check if an Element is enabled in Selenium WebDriver is helpful for you ...

Team,

QA acharya




How to check if element is disabled in Selenium Java

Post a Comment

0 Comments