Friday, 9 December 2016

Java + Selenium Code to test Product Existence in Flipkart

1.)  Download selenium-Java Web Driver  and include all jar files into your build path in eclipse and copy & run the below code u will get result.

http://www.seleniumhq.org/download/

import java.util.Iterator;
import java.util.Set;

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

public class SearchProduct {

public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.flipkart.com/");
driver.findElement(By.xpath("//input[@placeholder = 'Search for Products, Brands and More']")).sendKeys("sony camera");
driver.findElement(By.xpath("//button[@type='submit']")).click();
try{
 driver.findElement(By.xpath("//div[@data-aid='breadcrumb-container']/following-sibling::div/descendant::span[contains(text(),'results for')]")).getSize();
 System.out.println("Search results Found");
}
catch(Throwable t){
System.out.println("Element not Visible");
}
System.out.println("Pgm Ends");


}

}


Output:



No comments:

Post a Comment