Reputation: 13
I am in a situation where I have to expand the drop down and from the list of values after expansion, I have to select one value.
Could you please help in this?
Below is the code I have used so far:
List<WebElement> elements = driver.findElement(By.id("Some Value"));
for (WebElement element: elements)
{
new Actions(driver).sendKeys(Keys.Arrow_Down).perform();
if(Element.getText().equals("Cliam Document"))
{
element.click();
}
}
Upvotes: 0
Views: 234
Reputation: 223
Scenarios:
1. Store value into string where you want to perform click operation.
2. Store all Drop down values into List.
3. Using For each loop store all values into WebElement.
4. Get Text of each and every one value and store into string.
5. Compare each and every Actual string with Expected String.
6. If Expected string found within for each loop then click on WebElement.
String Expected_String = "Test";
List<WebElement> elements = driver.findElement(By.id("Some Value"));
for (WebElement element : elements)
{
String value = element.getText();
if (value.equalsIgnoreCase( Expected_String))
{
element.click();
break;
}
}
Upvotes: 0
Reputation: 195
You can select a values from Drop down in 3 ways,
In your case no need to use Action() class. You can use any method from above.
Check this Code:
Select se = new Select(driver.findElement(By.id("your ID")));
se.selectByIndex(your preferred index value);
Upvotes: 0
Reputation: 177
You can use below code :
to use the dropdownlist
Select select1 = new Select(driver.findElement(By.id("your identifier")));
select1.selectByVisibleText("Cliam Document");
Upvotes: 1