How to check if element is disabled in Selenium Java
isEnabled()
isEnabled() method in Selenium webdriver will verify and return true if the specified element is enabled. otherwise, it will return false.
Syntax:
boolean FirstName= driver.findElement(By.id(“fname”)).isEnabled();
System.out.print(FirstName);
Selenium Code :
Here Selenium Code to verify if the element is active or Deactive is given.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Login {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(“webdriver.chrome.driver”, “C:\\Software Program\\chromedriver.exe”);
WebDriver driver=new ChromeDriver();
driver.get(“https://www.facebook.com”);
//To verify that Element is Enabled or not
Boolean nn =driver.findElement(By.xpath(“//input[ @type=\”text\”]”)).isEnabled();
if(nn) {
System.out.println(“Element is Present”);
}
else {
System.out.println(” Element is not Present”);
}
}
}
Also Read
How to enter Text in text box using Selenium