java - Selenium : org. openqa.selenium.ElementNotInteractableException:

标签 java selenium selenium-webdriver geckodriver

这就是 HTML 的样子。

<select name="ctl00$bodyContent$ddl_Territory" onchange="javascript:setTimeout(&#39;__doPostBack(\&#39;ctl00$bodyContent$ddl_Territory\&#39;,\&#39;\&#39;)&#39;, 0)" id="ctl00_bodyContent_ddl_Territory" class="select2-container" style="margin-left: 3%;">
    <option selected="selected" value=""></option>
    <option value="675">ALASKA AK (OCRGA061A) - HCP</option>
    <option value="271">ALBANY GA (OCBDB041A) - HCP</option>
    <option value="125">ALBANY NY (OCBAA031A) - HCP</option>
    <option value="126">ALBANY NY (OCBAA032A) - HCP</option>
    <option value="426">ALBANY NY (OCRAA031A) - HCP</option>
    ....
    <option value="427">ALBANY NY (OCRAA031A) - HOSPITAL</option>

不断失败的自动化代码 -

Select territory = new Select(driver.findElement(By.name("ctl00$bodyContent$ddl_Territory")));
        System.out.println("selected");
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block 
           // Trying to figure if sleep is required or not.. 
            e.printStackTrace();
        }



        List<WebElement> optionList = territory.getOptions();
        for (WebElement webElement : optionList) {
            System.out.println(webElement.getText()); //this print nothing..empty line..confused
        }

        territory.selectByIndex(1); //exception thrown here

当我调用 selectByIndex 时,我得到 org.openqa.selenium.ElementNotInteractableException: 。我也尝试过 selectByValue 等,但没有帮助。 我确信 territory 指向正确的元素,因为 optionList 计数与 HTML 中的选项数量相同。但是不确定为什么文本没有在循环中打印以及为什么会出现异常..

驱动程序 - geckodriver-v0.18.0-win64

TIA!

更新1:webElement.isDisplayed()为所有选项打印falsegetLocation() 打印 X 和 Y 坐标的 0,0 ..

最佳答案

获取所有选项的替代方法如下

List<WebElement> optins = driver.findElements(By.xpath("//select[@name='ctl00$bodyContent$ddl_Territory']/options"));

通过可见文本选择的替代方法

driver.findElement(By.name("ctl00$bodyContent$ddl_Territory")).sendKeys("ALBANY NY (OCBAA031A) - HCP");

关于java - Selenium : org. openqa.selenium.ElementNotInteractableException:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45295567/

相关文章:

java - 事务中未到达finally{timer.cancel();}

java - "No Alert Open"在网站完全打开之前尝试输入登录凭据时

python - 用户 :pass proxies with selenium

java - 未从 div 获取值

python - 确认动态 html 表格中的文本后单击复选框

java - 由于我的 SpringBoot 应用程序,Swagger UI 未显示,每个端点需要 2 个查询参数

java - Spring & Java Generics - 在抽象 Controller 中获取一项服务的实例

java - 将 GUI 文本存储为 ResourceBundle(无本地化)?

selenium - org.openqa.selenium.InvalidCookieDomainException : Document is cookie-averse using Selenium and WebDriver

ruby - Selenium Webdriver 获取 cookie 值