-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImplicitWait.java
More file actions
45 lines (32 loc) · 1.38 KB
/
ImplicitWait.java
File metadata and controls
45 lines (32 loc) · 1.38 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
package selenium;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class ImplicitWait {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "D:\\software\\chromedriver_win32 (2)\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
// Introducing implicit waits
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("https://www.google.com/");
driver.findElement(By.xpath("//*[@name ='q']")).sendKeys("How stuff work");
// HOW TO HANDLE AUTO SUGGESTIONS
WebElement AllSuggestion = driver.findElement(By.xpath("//*[@id=\"downshift-1-input\"]"));
List<WebElement> AllSearch = AllSuggestion.findElements(By.tagName("li"));
System.out.println("Total Auto Suggestion:" + AllSearch.size());
for (int i = 0; i < AllSearch.size(); i++) {
String AllSuggestionList = AllSearch.get(i).getText();
String FinalResult ="Mysore";
if (AllSuggestionList.equalsIgnoreCase(FinalResult)) {
AllSearch.get(i).click();
System.out.println("you got selected:" + FinalResult);
break;
}
}
}
}