-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment204.java
More file actions
66 lines (46 loc) · 1.67 KB
/
Assignment204.java
File metadata and controls
66 lines (46 loc) · 1.67 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
package TestNGCLAssignments;
import java.time.Duration;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
/* "WAP Using iframe On below problem
1. Launch Google
2. Type ""Grotechminds"" and press enter button
3. Click on hamburger button available on right TOP corner(9 dots)
4.Click on Youtube
5.Search for grotechminds
6. Click on ""Subscribe"" button of grotechminds youtube channel
Note: Please do this using TestNG" */
public class Assignment204 {
@Test
public void GSearch() throws InterruptedException {
ChromeDriver driver = new ChromeDriver();
driver.get("https://www.google.com/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(20));
driver.findElement(By.name("q")).sendKeys("Grotechminds", Keys.ENTER);
Thread.sleep(2000);
WebElement b1 = driver.findElement(By.className("gb_A"));
b1.click();
driver.switchTo().frame(0);
List<WebElement> apps = driver.findElements(By.xpath("//div[@class='LVal7b ']/ul/li"));
int count = apps.size();
for (int i = 0; i < count; i++) {
WebElement sugg = apps.get(i);
if (sugg.getText().contains("YouTube")) {
sugg.click();
break;
}
}
String yt = driver.getWindowHandle();
driver.switchTo().window(yt);
WebElement ytsearch = driver.findElement(By.xpath("//form[@id='search-form']/div/div/input"));
ytsearch.sendKeys("grotechminds");
ytsearch.sendKeys(Keys.ENTER);
driver.findElement(By.xpath("//a[@aria-label='Subscribe']")).click();
}
}