-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment203.java
More file actions
74 lines (46 loc) · 2 KB
/
Assignment203.java
File metadata and controls
74 lines (46 loc) · 2 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
64
65
66
67
68
69
70
71
72
73
74
package TestNGCLAssignments;
import java.io.FileInputStream;
import java.io.IOException;
import java.time.Duration;
import java.util.Iterator;
import java.util.Set;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
//WAP using implicit Wait on Amazon payments page ?
public class Assignment203 {
@Test
public void amz_payment() throws EncryptedDocumentException, IOException, InterruptedException {
FileInputStream f1 = new FileInputStream(
"C:\\Users\\USER\\eclipse-workspace\\SeleniumBasics\\DDT\\Abhilash.xlsx");
Workbook w1 = WorkbookFactory.create(f1);
String un = w1.getSheet("Sheet4").getRow(0).getCell(0).getStringCellValue();
String pswd = w1.getSheet("Sheet4").getRow(0).getCell(1).getStringCellValue();
ChromeDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
driver.get("https://www.amazon.in/ref=nav_logo");
driver.manage().window().maximize();
driver.findElement(By.xpath("//span[.='Hello, sign in']")).click();
Thread.sleep(2000);
driver.findElement(By.name("email")).sendKeys(un);
driver.findElement(By.className("a-button-input")).click();
Thread.sleep(2000);
driver.findElement(By.name("password")).sendKeys(pswd);
driver.findElement(By.className("a-button-input")).click();
driver.findElement(By.id("twotabsearchtextbox")).sendKeys("mobiles", Keys.ENTER);
WebElement r1 = driver.findElement(By.xpath("((//span[@class='rush-component'])/a/div)[1]"));
r1.click();
Set<String> w2 = driver.getWindowHandles();
Iterator<String> I1 = w2.iterator();
String parent = I1.next();
String Childid = I1.next();
driver.switchTo().window(Childid);
driver.findElement(By.id("buy-now-button")).click();
driver.quit();
}
}