1

enter image description here

I want to select "India (+91)" from dropdown

Can anyone help me with this?

1

2 Answers 2

4

Use the below code:

WebElement countryUL= driver.findElement(By.xpath("//[@id='country_id']/ul"));
List<WebElement> countriesList=countryUL.findElements(By.tagName("li"));
for (WebElement li : countriesList) {
if (li.getText().equals("India (+91")) {
     li.click();
   }
}
3

It's simple, just you have to use Select method in WebDriver.

    WebElement countrydropdown=driver.findElement(By.id("country_id"));
    Select country=new Select(countrydropdown);
    country.selectByVisibleText("India (+91)");
1
  • 1
    Hi don't think select will work with non select tags. you can use select only with <select> tag i believe
    – PDHide
    Dec 10, 2019 at 10:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.