I have also got a autocomplete text box options, so for that i have just created the method which used to control it, may this help you please modify it with your use:-
public static void selectAutoSearchText(By selectBoxElement,By textBoxElement, By dropdownElement, String textValue, String matchingValue, WebDriver driver, WebDriverWait wait) throws InterruptedException
{
try {
wait.until(ExpectedConditions.visibilityOfElementLocated(selectBoxElement)).click();
WebElement searchBox= wait.until(ExpectedConditions.visibilityOfElementLocated(textBoxElement));
searchBox.sendKeys(textValue);
Thread.sleep(1000);
WebElement waitElement= wait.until(ExpectedConditions.visibilityOfElementLocated(dropdownElement));
Thread.sleep(1000);
List<WebElement> dropdownList= waitElement.findElements(By.tagName("tr"));
//System.out.println(dropdownList);
//System.out.println(dropdownList.size());
for(WebElement listElement :dropdownList)
{
//System.out.println(listElement.getText());
if(listElement.getText().equals(matchingValue))
{
listElement.click();
break;
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I have used both Explicit Wait
and Thread.sleep
just because by drop down options value loaded after some time, so in some cases it failed to select options so i used the thread.sleep to reduce it.
In this you just need to pass the Xpath of these values and text which you will enter and matching value is for select that country name on which you want click for select that option.
I have used tag name <tr>
you can change it according to your options tag because it can be Button
or Span
tag also.