-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chosen.java
55 lines (42 loc) · 1.23 KB
/
Chosen.java
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 utilities;
import org.openqa.selenium.*;
import java.util.List;
/**
* Models a Chosen dropdown, providing helper methods to select options.
* Author:[email protected]
* Use getOptions method to chcek the list size.
*
*/
public class Chosen {
private final WebElement element;
public Chosen(WebElement element) {
this.element = element;
}
public List<WebElement> getOptions() throws InterruptedException {
element.click();
Thread.sleep(2000);
List<WebElement> options = element.findElements(By.className("active-result"));
for (WebElement e : options) {
System.out.println(e.getText());
}
return options;
}
public void selectByIndex(int index) throws InterruptedException {
element.click();
Thread.sleep(2000);
List<WebElement> options = element.findElements(By.className("active-result"));
System.out.println("Selecting option: " + options.get(index).getText());
options.get(index).click();
}
public void selectByValue(String value) throws InterruptedException {
element.click();
Thread.sleep(2000);
List<WebElement> options = element.findElements(By.className("active-result"));
for (WebElement e : options) {
if (e.getText().contains(value)) {
e.click();
break;
}
}
}
}