org.openqa.selenium.ElementNotInteractableException:当我尝试在下拉列表中选择值时

时间:2017-07-15 22:46:16

标签: java selenium selenium-webdriver

我正在尝试使用Select,但获得异常 - ElementNotInteractableException。 我该如何解决这个问题?

    <select id="month0" class="custom-select" name="month0" aria-required="true" tabindex="-1" aria-hidden="true" style="opacity: 0; position: absolute; left: -9999px;" aria-invalid="true">
        <option value="">Month</option>
        <option value="Jan">January</option>
        <option value="Feb">February</option>
        <option value="Mar">March</option>
        <option value="Apr">April</option>
        <option value="May">May</option>
        <option value="Jun">June</option>
        <option value="Jul">July</option>
        <option value="Aug">August</option>
        <option value="Sep">September</option>
        <option value="Oct">October</option>
        <option value="Nov">November</option>
        <option value="Dec">December</option>
</select>
<span id="month0-button" class="ui-selectmenu-button ui-widget ui-state-default ui-corner-all errorInput" tabindex="0" role="listbox" aria-expanded="false" aria-owns="month0-menu" aria-haspopup="true" aria-required="true" style="width: 99px;" aria-activedescendant="ui-id-5" aria-labelledby="month0-label ui-id-5 month0-required" aria-disabled="false" aria-invalid="true" aria-describedby="month0-error">
        <span class="ui-icon ui-icon-triangle-1-s"/>
        <span class="ui-selectmenu-text">Month</span>
</span>
<span id="month0-required" tabindex="-1" aria-hidden="true" style="opacity:0; position:absolute; left:-9999px">Required</span>

我的代码:

Select selectElement = new Select(monthDropDown);
selectElement.selectByVisibleText(month);
//or selectElement.selectByValue(month)  - don't working too
//or selectElement.selectByIndex("2")    - don't working too

使用的定位器:

@FindBy(id = "month0")
WebElement monthDropDown;

@FindBy(id = "day0")
WebElement dayDropDown;

@FindBy(id = "year0")
WebElement yearDropDown;

1 个答案:

答案 0 :(得分:0)

什么是&#39; month&#39;你的代码?

使用selectByIndex()

使用下面的代码。您的代码似乎有拼写错误。

selectElement.selectByIndex(2);