Monday, 10 November 2014

How to verify if button is enabled in Selenium Webdriver in Java?

How to verify if button is enabled in Selenium Webdriver in Java? 



package com.snapdeal;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class TestIsEnabled {
    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();
        try {
            driver.get("https://login.yahoo.com/config/mail?&.src=ym&.intl=in");
            WebElement e = driver.findElement(By.id(".save"));
            boolean actual = e.isEnabled();
            if (actual) {
                System.out.println("Button is enabled");
            } else {
                System.out.println("Button is not enabled");

            }

        } catch (Exception ex) {
            System.out.println("Exception" + ex.getMessage());

        } finally {
            driver.close();
        }
    }
}
 

No comments:

Post a Comment