Monday, June 9, 2014

How to get the text which is not visible in web page but it is there in HTML code ? And how to check whether check box is enabled or not ?

Note: use  getAttribute("textContent") method to get the hidden text.

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Facebook {
    public static void main(String[] args) {
    WebDriver driver = new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
    driver.get("https://www.facebook.com/");
    String value= driver.findElement(By.xpath("//a[@title='Go to Facebook Home']")).getAttribute("textContent");
    System.out.println("Value is : " + value);
    boolean box= driver.findElement(By.xpath("//input[@type='checkbox']")).isEnabled();
    System.out.println(box);
    driver.close();
    }
}

1 comment:

  1. Hi dude, I unable to understand 1 statement.

    String value= driver.findElement(By.xpath("//a[@title='Go to Facebook Home']")).getAttribute("textContent");

    In this statement, where you got this string "textContent". In web I have not found it.

    ReplyDelete