-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAmazonPhones.java
More file actions
44 lines (32 loc) · 1.37 KB
/
Copy pathAmazonPhones.java
File metadata and controls
44 lines (32 loc) · 1.37 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
package week3HomAssignments;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class AmazonPhones {
public static void main(String[] args) {
// TODO Auto-generated method stub
ChromeDriver cc = new ChromeDriver();
cc.manage().window().maximize();
cc.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
cc.get("https://www.amazon.in/");
cc.findElement(By.xpath("//input[@id=\'twotabsearchtextbox\']")).sendKeys("phones");
cc.findElement(By.xpath("//input[@id='nav-search-submit-button']")).click();
List<WebElement> mobiles = cc.findElements(By.xpath("//span[@class='a-price-whole']"));
int total = mobiles.size();
System.out.println("Total no.of Mobiles :"+total);
List<Integer> numbers = new ArrayList<Integer>();
for(WebElement result: mobiles) {
String price = (result.getText());
String priceText = price.replaceAll("[^0-9]", "");
int sortedprice = Integer.parseInt(priceText);
numbers.add(sortedprice);
}
Collections.sort(numbers);
System.out.println(numbers);
}
}