无法使用selenium java在iframe中选择下拉列表

时间:2018-01-04 10:59:44

标签: java selenium iframe dropdown

我无法从以下网址的iframe中的下拉列表中选择任何值:https://bootsnipp.com/snippets/featured/button-dropdown-select

以下是我的代码:

public class SelectDropdown {

public static void main(String[] args) throws InterruptedException {
    System.setProperty("webdriver.chrome.driver", "C:\\ChromeDriver_2.33\\chromedriver.exe");
    WebDriver chrome = new ChromeDriver();
    chrome.get("https://bootsnipp.com/snippets/featured/button-dropdown-select");

    chrome.switchTo().frame("snippet-preview");
    System.out.println("frame passed");

    WebElement dropDownLocation = chrome.findElement(By.xpath("//select[@class = 'selectpicker'][5]"));
    System.out.println("dropdown found");

    Select abc = new Select(dropDownLocation);
    System.out.println("dropdownLocation found");

    abc.selectByVisibleText("Relish");
    System.out.println("dropdown value selected");

}

}

以下是我得到的例外情况:

  

线程中的异常" main"   org.openqa.selenium.ElementNotVisibleException:元素不可见:   元素当前不可见,可能无法操纵

1 个答案:

答案 0 :(得分:0)

WebElementxpath匹配bs-docs-example,您正在寻找的下拉列表以及WebElement dropDownLocation = chrome.findElement(By.xpath("//*[not(@class='bs-docs-example')]/select[@class = 'selectpicker'][5]")); 类下的同级广告的子元素。您尝试找到没有该类的元素。

File > New > New Custom Project