forked from TalhaBinAshraf1/SeleniumTestingInternetHerokuApp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoComplete.java
More file actions
47 lines (36 loc) · 1.38 KB
/
Copy pathAutoComplete.java
File metadata and controls
47 lines (36 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
46
47
package allTests;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import utility.FrameworkConstants;
public class AutoComplete {
public static void main(String[] args) {
System.setProperty(FrameworkConstants.CHROME_DRIVER_KEY,FrameworkConstants.CHROME_DRIVER_PATH);
WebDriver driver = new ChromeDriver();
driver.get("https://in.yahoo.com/?p=us");
System.out.println(driver.getTitle());
WebElement searchBox = driver.findElement(By.xpath("//input[@id='uh-search-box']"));
searchBox.sendKeys("selenium");
WebDriverWait wait = new WebDriverWait(driver, 4);
List<WebElement> resultList = wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//input[@id='uh-search-box']/following-sibling::div//ul/li")));
System.out.println("Result no are : "+resultList.size());
if(resultList.size()>0) {
for(WebElement result:resultList) {
System.out.println(result.getText());
if(result.getText().equalsIgnoreCase("selenium download")) {
System.out.println("To click the result page");
result.click();
break;
}
}
}
else {
System.out.println("Nothing to select");
}
// driver.quit();
}
}