mercredi 28 décembre 2016

how to select element by value from dropdown with java & selenium ?

am trying to select country code from dropdown where the elements has no index or ID i can only select by value, i tried using SelectByValue & VisibleText Both didnt work also tried to list element and loop on them but didnt work either

here is the code

public void selectInDropDownMenuCountryCode(final WebDriver driver, final By selector, final String selection)
{
    _wait.until(ExpectedConditions.visibilityOfElementLocated(selector));
    final Select select = new Select(driver.findElement(selector));
    //select.selectByVisibleText(selection);
    //select.selectByValue(selection);
     String code;

      List<WebElement> optionsD = select.getOptions();

    for (WebElement option : optionsD) 
    {
         code = option.getAttribute("value");
        if (code == selection)
        {
            option.click();
            break;
        }       

    }
}

Screenshot of html here is the html code




Aucun commentaire:

Enregistrer un commentaire