It is an automation of an desktop eCommerce website being used on a Browserstack mobile emulator. Basically it is test automation of MobileWeb application.
It is a drop down of 'Sold To' list items, contains probably nearly a 1000 items. Once user clicks the drop down box, a (filter)search box appears as part of the list and when user enters the filter text, the list is filtered to show those items which match the input string. Filter string is such that it results in only one result. Automation script has to click that one result 'list item'.
I tried to retrieve the list of items using the cssSelector as
'div#myDropdown>a.mobile-soldto-list>span'
, like
List<WebElement> listItems = driver.findElements(By.cssSelector("div#myDropdown>a.mobile-soldto-list>span"));
which returned 944 items which checks out with what Browser dev tools also showed.
Then, I tried to iterate through each WebElement having a specific option text like..
for(WebElement listItem: listItems) {
if(listItem.getText().startsWith("SOME TEXT")) {
System.out.println("text="+listItem.getText());
listItem.click();
break;
}
}
The text printed out by System.out matches the "SOME TEXT". But after clicking happened, the drop down box collapsed to the original list as like the page was rendered the first time. It is suspected that the code could not click on the list item, instead clicked on the dropdown box and the list collapsed as in original position.
What is the secret sauce, I am missing and how can I correct it ?


I use Actions class to work with dropdown search functionalities.
it will move the driver down to the result and click on it.