Automation Using Selenium Webdriver

Wednesday, 12 October 2016

How to verify a Text present in the loaded page through Web Driver

       How to verify a Text present in the loaded page through Web Driver
   
Verify  "Flights"  a text present in a goibibo.com

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

public class VerifyTextWebpage {

public static void main(String[] args) {
// TODO Auto-generated method s
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.goibibo.com/");
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();

String expText="Flights";
//verify flights text Available are not
String actText=driver.findElement(By.xpath("html/body/div[1]/div[1]/ul/li[1]/a/span")).getText();
if(actText.contains(expText)){
System.out.println("1)Expected Text"+expText+"Preent in the page");
}else{
System.out.println("1)Expected Text"+expText+" not Preent in the page");
}

}

}

//OutPut:1)Expected TextFlightsPreent in the page





No comments:

Post a Comment