-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample3_3.java
More file actions
55 lines (41 loc) · 1.8 KB
/
Example3_3.java
File metadata and controls
55 lines (41 loc) · 1.8 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
package com.SeleniumTestingSamples.Examples;
import java.time.Duration;
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.Select;
//Drop Down Example by Value or Index
public class Example3_3 {
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
String URL = "https://selenium08.blogspot.com/2019/11/dropdown.html";
driver.get(URL);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10000));
//Locate drop down element on web page by By.xpath
WebElement dropdown = driver.findElement(By.xpath("//select[@name='country']"));
//Verify the drop down is enabled and visible.
if(dropdown.isEnabled() && dropdown.isDisplayed()) {
System.out.println("Dropdown is enabled and visible");
}else {
System.out.println("Dropdown is not visible");
}
// Create an object of Select class and pass the drop down of type WebElement as an argument.'
Select select = new Select(dropdown);
// Verify that dropdown does not allow the multiple selections.
if(select.isMultiple()) {
System.out.println("Dropdown list accepts multiple choices");
}else {
System.out.println("Dropdown list does not accept multiple choices");
}
// Call getOptions() method to get all get size of list. options of list.
int listSize = select.getOptions().size();
System.out.println("List size: "+ listSize);
// Select the option "India" by sending visible text.
select.selectByVisibleText("India");
//Check that "India" is selected as an option or not.
String getText = select.getFirstSelectedOption().getText();
// Close the browser.
driver.close();
}
}