How To Verify Element is Enabled or Disabled in Selenium

 How To Verify Element is Enabled or Disabled in Selenium Webdriver?

To verify that the target element (Button, Check box, Dropdown, text box, Radio Button, Icons, etc ) are enabled or disabled use isEnabled() Method to check element is enabled or disabled.
Here, Element is diable means element is present on the webpage but not in editable mode.



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

Syntax:
Syntax to verify whether the element present on webpage is enabled or disabled are given below.

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

To check when there is a condition where we need to take any action based on element status.

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 Present");
     }
     else {
           System.out.println("NO ! Element is not Present");
     }
 
}
}

How To verify Element is present or visible in selenium using Java?

isDisplayed()
To check element (checkbox, dropdown, Button, Textbox, RadioButton, link, etc)  is present or visible on the page use isDisplayed() method.
isDisplayed() is a method used to verify and return true if the specified element is displayed. Else it will return false.

Syntax:

 driver.findElement(By.id("Fname")).isDisplayed();

To check and verify the visibility of the element on a webpage isDisplayed() Method is used. 

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 Displayed
           Boolean nn =driver.findElement(By.xpath("//input[ @type=\"text\"]")).isDisplayed();
     if(nn) {
           System.out.println("Yes ! Element is Present");
     }
     else {
           System.out.println("NO ! Element is not Present");
     }
 
}
}


Hope !!! The above Tutorial of "How to verify the element is enabled in selenium helpful for you ...

Team , 
QA acharya 

agTs : How To Test For Disabled Elements , How to  check disable element in selenium webdriver , How to check if element is disabled in selenium Java, How to handle disabled elements in selenium webdriver java

How To Verify Element is Enabled or Disabled  in Selenium


Admin-Mumbai office

Post a Comment

Previous Post Next Post