How To Verify Element is Enabled or Disabled in Selenium

.
Handling Disable and Enable Field 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 ) is enabled or disabled use the isEnabled() Method to check element is enabled or disabled.
Here, Element is diable means the element is present on the webpage but not in editable mode.


Handling Disable and Enable Field 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:
Syntax to verify whether the element present on the webpage is enabled or disabled is 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 Do Verify Elements Present 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. Otherwise, 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 on "How to verify the element is enabled in selenium helpful for you ...

Team, 
QA acharya 

Tags: How To Test For Disabled Elements, How to  check to disable element in Selenium web driver, How to check if the element is disabled in Selenium Java, How to handle disabled elements in Selenium web driver java

How To Verify Element is Enabled or Disabled  in Selenium

Post a Comment

0 Comments