forked from nbhat1/Selenium-JavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebDropdown.java
More file actions
58 lines (40 loc) · 1.65 KB
/
Copy pathwebDropdown.java
File metadata and controls
58 lines (40 loc) · 1.65 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
package main.webdriver;
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.firefox.FirefoxDriver;
public class webDropdown {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir") + "\\GecoDriver\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
/*
driver.get("http://www.xe.com/");
driver.findElement(By.xpath("//*[@id='to']")).click();
driver.findElement(By.xpath("//*[@id='to']")).sendKeys("INR - Indian Rupee");
driver.findElement(By.xpath("//*[@id='ucc_go_btn_svg']/a/polygon")).sendKeys(Keys.ENTER);
*/
driver.get("http://www.wikipedia.com");
WebElement dropdown = driver.findElement(By.xpath(".//*[@id='searchLanguage']"));
List<WebElement> dropOptions = dropdown.findElements(By.tagName("option"));
/*
for(int i=0 ; i< dropOptions.size(); i++) {
String name = dropOptions.get(i).getText();
//System.out.println(name);
if (name.contentEquals("English") ){ // Print English when English language comes.
System.out.println(name);
}
}
System.out.println(dropOptions.size());
//driver.close();
*/
System.out.println("************Print All Links on page********");
WebElement links = driver.findElement(By.xpath("//*[@id='www-wikipedia-org']"));
List<WebElement> allLinksLanguage = links.findElements(By.tagName("div"));
for (int i = 0; i<allLinksLanguage.size();i++){
System.out.println(allLinksLanguage.get(i).getText());
}
}
}