Reputation: 161
I had the following code for my select:
Select entitySelector = new Select(entitySettingsPage.entitySelector);
entitySelector.selectByVisibleText(entityName);
but now the developer changed the select to button because he had to implement a change. This is how it looks now:
<button _ngcontent-c8="" aria-expanded="true" aria-haspopup="true" class="btn btn-default dropdown-toggle" data-toggle="dropdown" type="button" id="entity_settings_glossary_picker_button">
Choose an entity
<span _ngcontent-c8="" class="caret" id="entity_settings_glossary_picker_caret"></span>
how do I work around this change? I also want to mention that the elements from the drop-down have ids like the following: entity_settings_glossary_picker_option_1
If it would have been a string at the end instead of a number, it would have been easy to write a function to identify my element. How do I know what is going to be the number of the element I create? (I always create a new entity for my tests).
Upvotes: 0
Views: 3324
Reputation: 17553
Use below code :
WebElement dropdown = driver.findElement(By.id("entity_settings_glossary_picker_button"));
dropdown.click(); // assuming you have to click the "dropdown" to open it
List<WebElement> options = dropdown.findElements(By.tagName("li"));
for (WebElement option : options)
{
if (option.getText().equals(searchText))
{
option.click(); // click the desired option
break;
}
}
Upvotes: 1