문제

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