-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDropDown.java
More file actions
50 lines (39 loc) · 1.44 KB
/
Copy pathDropDown.java
File metadata and controls
50 lines (39 loc) · 1.44 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
package chapter7;
import java.util.List;
import org.openqa.selenium.Point;
import org.openqa.selenium.Rectangle;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
public class DropDown {
public static void main(String[] args) {
ChromeDriver driver = new ChromeDriver();
driver.get("https://letcode.in/");
driver.manage().window().maximize();
driver.get("https://letcode.in/dropdowns");
// Select the apple using visible text
WebElement fruitsEle = driver.findElementById("fruits");
Select fruits = new Select(fruitsEle);
System.out.println(fruits.isMultiple());
fruits.selectByVisibleText("Banana");
WebElement herosEle = driver.findElementById("superheros");
Select heros = new Select(herosEle);
// check multiple
boolean multiple = heros.isMultiple();
System.out.println(multiple);
heros.selectByIndex(2);
heros.selectByValue("ca");
heros.selectByVisibleText("Iron Man");
heros.deselectByIndex(2);
List<WebElement> allSelectedOptions = heros.getAllSelectedOptions();
for (WebElement hero : allSelectedOptions) {
System.out.println(hero.getText());
}
WebElement countryEle = driver.findElementById("country");
Select country = new Select(countryEle);
country.selectByValue("India");
WebElement selectedCountry = country.getFirstSelectedOption();
System.out.println(selectedCountry.getText());
driver.quit();
}
}