FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 290   



isDisplayed() and isEnabled() Methods are used to check the visibility of the web elements. These web elements can be buttons, drop boxes, checkboxes, radio buttons, labels etc.

  1. isDisplayed(): Verifies whether this element displayed or not?

  2. isEnabled() : Is the element currently enabled or not ? this will generally return true for everything but for disabled input elements returns false.

package com.selenium.practise;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Verification {
    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "E:\\Soft Wares\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        String Url = "https://google.com";
        // Open the application in chrome browser
        driver.get(Url);

        String expectedTitle = "Google";
        String actualTitle = driver.getTitle();
        // verification 

        if (expectedTitle.equals(actualTitle)) {
            System.out.println("Title verification Successful");
        }
        else {
            System.out.println("Verification Failed");
        }
        // verify if the “Google Search” button is displayed and print the result

        boolean submitEnabled = driver.findElement(By.id("gb_70")).isEnabled();

        boolean submitDisplayed = driver.findElement(By.name("btnK")).isDisplayed();

        if (submitDisplayed==true && submitEnabled==true) {

            driver.findElement(By.id("gb_70")).click();
            System.out.println("verification success for isDisplayed() && isEnabled() methods");

        }

        // close the web browser
        driver.close(); 
    }
}

Output :
Title verification is Successful
Verification success for isDisplayed() && isEnabled() methods





On By


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News