Domanda

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();   
}
È stato utile?

Soluzione

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

Altri suggerimenti

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();   
    }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top