Pergunta

Please verify my code for the following URL with credentials as

URL: http://ec2-54-226-18-214.compute-1.amazonaws.com/w/user.html?action=login

username: root

password: 12345678

code:

d1.switchTo().window("modalbox");

WebElement select = d1.findElement(By.id("getSelectedCountry"));
List<WebElement> options = select.findElements(By.tagName("Qatar"));

for (WebElement option : options) {
    if("Qatar".equals(option.getText().trim()))
    option.click();   
}
Foi útil?

Solução

This can help,

WebElement attribute = driver.findElement(By.id("getSelectedCountry");
attribute.sendKeys("Qatar");

Also adding a "wait" After selecting the country can help as it takes times to load

Outras dicas

You are trying to search the element by "value" and using "By" as tagName. Please use "option" instead. Please check your code as below:

    d1.switchTo().window("modalbox");
    WebElement select = d1.findElement(By.id("getSelectedCountry"));
    List<WebElement> options = select.findElements(By.tagName("option"));

    for (WebElement option : options) {

    if("Qatar".equals(option.getAttribute("value")))

    option.click();   
    }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top