Friends,
I have a situation where I need to click on a dropdown list and select any value displayed. The dropdown is identified by the following piece of code
<select id="order_unit_line_rate_806782_is_addenda_enabled" class="selects_for_487886" onchange="select_addendum(806782, this);dateShowMemory(this.options[this.selectedIndex].value, '806782');" uniqueattr="Dynamic Site Accelerator / Dynamic Site Accelerator / Additional Usage Commitment / drop down" name="order_unit_line_rate[806782][is_addenda_enabled]">
<option value="0" uniqueattr="Dynamic Site Accelerator / Dynamic Site Accelerator / Additional Usage Commitment / Fee"> Fee </option>
<option value="1" uniqueattr="Dynamic Site Accelerator / Dynamic Site Accelerator / Additional Usage Commitment / See Attached Addendum"> See Attached Addendum </option>
where the "select" and "option" tags are in a nested hierarchy . i am able to click on the dropdown list and display the items by doing this
List<WebElement> dropDownLists = driver.findElements(By.tagName("select"));
for (WebElement l : dropDownLists) {
if (l.getAttribute("uniqueattr").equalsIgnoreCase("Dynamic Site Accelerator / Dynamic Site Accelerator / Additional Usage Commitment / drop down")) {
l.click();
} // end if
} // end for
But I am unable to traverse further to click on the options in the dropdown :(.
This is what i tried but which is not working
List<WebElement> newList = driver.findElements(By.tagName("option"));
for (WebElement ll : newList) {
if (ll.getAttribute("uniqueattr").equalsIgnoreCase("Dynamic Site Accelerator / Dynamic Site Accelerator / Additional Usage Commitment / Straight Line Commitment")) {
ll.click();
}
}
Retrieve the label, index or value of the option you want to click like this
List<WebElement> dropDownLists = driver.findElements(By.tagName("select"));
for (WebElement l : dropDownLists)
{
List<WebElement> newList = l.findElements(By.tagName("option"));
for (WebElement ll : newList)
{
if (ll.getAttribute("uniqueattr").equalsIgnoreCase("Dynamic Site Accelerator / Dynamic Site Accelerator / Additional Usage Commitment / Straight Line Commitment"))
{
SelectElement select = new SelectElement(l);
select.SelectByValue(ll.getAttribute("value"));
}
}
}
Thats what the Select is for..
do something like:
Select dropDown = new Select(dropDownElement);
for (WebElement option : dropDown .getOptions()){
if(!option.isSelected()){
option.click();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.