-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAmazonAssignment.java
More file actions
64 lines (48 loc) · 1.91 KB
/
AmazonAssignment.java
File metadata and controls
64 lines (48 loc) · 1.91 KB
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
package odev;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class AmazonAssignment {
private WebDriver driver;
@Before
public void setUp() {
System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver");
driver = new ChromeDriver();
driver.get("http://www.amazon.com/");
}
@After
public void tearDown() {
driver.quit();
}
@Test
public void testSearch() {
WebElement SearchElement = driver.findElement(By.id("twotabsearchtextbox"));
SearchElement.sendKeys("Selenium Webdriver Book");
WebElement searchIcon = driver.findElement(By.id("nav-search-submit-button"));
searchIcon.click();
List<WebElement> books = driver.findElements(By.xpath("//div[@class='s-result-item s-asin sg-col-0-of-12 sg-col-16-of-20 sg-col sg-col-12-of-16']"));
if (books.size() > 0) {
String title, price;
for (int i = 0; i < books.size(); i++) {
title = books.get(i).findElement(By.cssSelector("h2")).getText();
price = books.get(i).findElement(By.cssSelector("div[class='a-section a-spacing-none a-spacing-top-small']")).getText();
boolean found = false;
if(price.contains("Paperback")) {
found = true;
String[] price1 = price.split("\n");
System.out.println("Book title is: "+title + "\n"+ "Book Price is:"+ price1[1] +"."+price1[2]);
System.out.println("<======================================>");
}
if(!found) {
System.out.println("Book title is: "+title + "\n"+ "Book Price is:"+"No paperback price");
System.out.println("<======================================>");
}
}
}
}
}