2017-07-15 38 views
-1

我試圖使用Select,但得到一個異常 - ElementNotInteractableException。 我該如何解決這個問題?org.openqa.selenium.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; 
+0

嘗試使用click代替。 Driver.findElement => element.click –

+0

你還試過了什麼?你沒有包括使用的定位器或你正在尋找的東西。此外,用戶界面的屏幕截圖很好,但您應該始終發佈HTML並將其格式化爲代碼。截圖將最終消失,使這個問題變得不那麼有用。 – JeffC

回答

0

什麼在你的代碼是 'month'?

對於使用以下代碼selectByIndex()

使用。您的代碼似乎存在拼寫錯誤。

selectElement.selectByIndex(2); 
+0

month - 這是一個字符串。 selectElement.selectByIndex(2) - 沒有幫助 –

+0

@Vadim - 它的價值是什麼? selectByIndex()解決了你的問題嗎? – Kapil