Friday, September 13, 2019

How to check element in Enabled or not | Selenium Automation



How to check element in Enabled or not:



In Selenium, before clicking or checking the specific element we need check whether specific element is enabled or not. We use this method frequently. This method returns true or false based on the element status.

 If element is enabled this method returns displays as “True” and if element is not enabled this method returns as disabled.

Let us see the example with Google search Button.

Syntax:

Element.isEnabled();


We need to check whether Search Button is enabled or not on google home page.



Complete code to check button is enabled or not:
package practise;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class ElementEnabledOrNot {

    static WebDriver driver;

    public static void main(String args[]) throws InterruptedException {
        //System.setProperty("webdriver.chrome.driver", "‎⁨path");
        driver = new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        driver.get("https://www.google.com/");
        Thread.sleep(5000);
        Boolean searchButtonEnabled = driver.findElement(By.xpath("(//input[@value='Google Search'])[2]")).isEnabled();
       
        System.out.println(searchButtonEnabled);
       
    }
   
}



Console output:






No comments:

Post a Comment

If any suggestions or issue, please provide