Question

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();   
}
Was it helpful?

Solution

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

OTHER TIPS

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();   
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top