Reputation: 765
In my testing UI, I need to automate a case as this in selenium java.
1. To click an icon, so that the pop-up list will be shown up,
2. then to select an item from the pop-up list.
But I am clueless how this can be done from following html code. This is the code after the icon has been clicked.
<ul class="pull-right header-helpers">
<li class="helpers-user hide-min-width"> ... </li>
<li class="helpers-help hide-min-width"> ... </li>
<li class="dropdown user-dropdown open">
<div class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<div>...</div>
</div>
<div class="dropdown-backdrop"></div>
<ul class="dropdown-menu dropdown-menu-right">
<li class="dropdown-menu-item">
<a action = "Option-A"/>
</li>
<li class="driver" role="separator"></li>
<li class="dropdown-menu-item">
<a action = "Option-B"/>
</li>
<li class="driver" role="separator"></li>
</ul>
</ul>
If icon hasn't been clicked, line 4 would be as this:
<li class="dropdown user-dropdown">
Thanks for the help.
Upvotes: 0
Views: 58
Reputation: 8489
Wait for the dropdown value you want to select and click it. This is to select the option A in the dropdown. You can replace option value with params and handle dynamically to select required option.
WebDriverWait wait = new WebDriverWait(driver, 60);
WebElement dropdown= wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".dropdown-menu a[action='Option-A']")));
dropdown.click();
Upvotes: 1