Wednesday, February 26, 2014

Validating text on the Webelement(Field) on the web page

import org.openqa.selenium.By; //.By - here meanse importing By methond from selenium package

import org.openqa.selenium.WebElement;//.WebElement - importing WebElement method from selenium package
//For accessing webelements on web page
import org.openqa.selenium.WebDriver;//.WebDriver - importing WebDriver element from selenium package
//WebDriver is used to access drivers like Firefox driver, chrome .....
import org.openqa.selenium.firefox.*;
//Expecially for firefoxdriver
public class TextValidationinthewebpage {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
WebDriver driver1 = new FirefoxDriver();//open firefox
driver1.get("http://homedepot.com");//open the website

//WebElement element1= driver.findElement(By.xpath("//input[@id='searchFocus']"));
//element1.sendKeys("trimmer");
WebElement element2 = driver1.findElement(By.xpath("//label[@id='lblSearch']")); //looking for SearchAll field
//element2.click();
String s= element2.getText(); //extracting default text of searchall field
System.out.println(s);
if(s.equals("What can we help you find?")) //string comparison
    //if(s.equalsIgnoreCase("What can we help you find.?")) //this will compare by ignoring case
System.out.println("test case pass");
else
System.out.println("test case fail");



//if (s=="What can we help you find?") then

    }

}

No comments:

Post a Comment