質問

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();   
}
役に立ちましたか?

解決

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

他のヒント

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();   
    }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top