-
Notifications
You must be signed in to change notification settings - Fork 0
/
SolutionThree.java
67 lines (53 loc) · 1.89 KB
/
SolutionThree.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.test;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import java.io.File;
import java.io.FileInputStream;
//import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterTest;
public class NewTest {
WebDriver driver;
@BeforeTest
public void beforeTest() {
System.setProperty("webdriver.chrome.driver", "/home/ajit/Documents/selenium/chromedriver");
driver = new ChromeDriver();
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://www.pepperfry.com/");
}
@Test
public void f() throws InterruptedException, IOException {
File file = new File("/home/ajit/Documents/selenium/AjitQ3.xls");
FileInputStream fin = new FileInputStream(file);
HSSFWorkbook wbook = new HSSFWorkbook(fin);
HSSFSheet sheet = wbook.getSheet("Sheet1");
int rowCount = sheet.getLastRowNum();
for (int i = 0; i <= rowCount; i++) {
String words = sheet.getRow(i).getCell(0).getStringCellValue();
WebElement searchTxtBox = driver.findElement(By.id("search"));
searchTxtBox.clear();
searchTxtBox.sendKeys(words + Keys.ENTER);
try {
driver.findElement(By.xpath("//li[contains(text(),'Relevance')]")).click();
driver.findElement(By.xpath("//a[contains(text(),'Price Low to High')]")).click();
} catch (NoSuchElementException e) {
System.out.println("No product");
}
}
}
@AfterTest
public void afterTest() {
driver.quit();
}
}