2014-09-05 115 views
2

以下是HTML元素不可見:元素當前不可見,不能被操縱 - 硒的webdriver

<div id="form1:customertype" class="ui-selectonemenu ui-widget ui-state-default ui-corner-all ui-state-hover" style="width: 165px;"> 
    <div class="ui-helper-hidden-accessible"> 
     <select id="form1:customertype_input" name="form1:customertype_input" tabindex="-1"> 
     <option value="S">Staff</option> 
     <option value="C">Customer</option> 
     <option value="N">New To Bank</option></select></div> 
    <div class="ui-helper-hidden-accessible"><input id="form1:customertype_focus" name="form1:customertype_focus" type="text" readonly="readonly"></div> 
    <label id="form1:customertype_label" class="ui-selectonemenu-label ui-inputfield ui-corner-all" style="width: 149px;">Staff</label> 
    <div class="ui-selectonemenu-trigger ui-state-default ui-corner-right ui-state-hover"><span class="ui-icon ui-icon-triangle-1-s ui-c"></span></div></div> 

類的樣式表=「UI輔助隱藏可訪問」是

ui-helper-hidden-accessible { 
     border: 0; 
     clip: rect(0 0 0 0); 
     height: 0px; 
     margin: -1px; 
     overflow: hidden; 
     padding: 0; 
     position: absolute; 
     width: 0px; 
    } 

以下是我的代碼

WebElement customerType = driver.findElement(By.id("form1:customertype_input")); 
    Select select = new Select(customerType); 
    select.selectByVisibleText("New To Bank"); 

當我嘗試從下拉菜單中選擇「新建行」我得到的例外 元素不可見:元素當前不可見,可能無法操作 - 硒webdriver

我試過WebDriverWait技術,但沒有用,任何想法?

+0

是否打開下拉菜單? – 2014-09-05 06:27:35

+0

可能是選擇下拉列表包裝。這通常發生在創建爵士樂下拉菜單時。檢查它是否真的隱藏。 – Vinay 2014-09-05 06:33:44

+0

是的手動下拉打開,但不是從代碼。該下拉菜單在頁面上直觀顯示。 – 2014-09-05 06:42:52

回答

0

嘗試customerType進行點擊您的創建對象之前選擇

+0

同樣的結果:(我得到這一行的異常 select.selectByVisibleText(「New To銀行「); – 2014-09-08 10:38:39

+0

使用其他標識符點擊內容的索引,將所有選項標籤放入列表中,並按索引編號2選擇_新到銀行選項 – 2014-09-08 13:30:05

0

嗯,我發現周圍的工作,以解決我的問題,但我不開心的與此有關。無論如何,我所做的是集中在通過點擊控制下拉菜單的div元素,然後發送箭頭鍵兩次,然後按Enter鍵。這選擇我想要的選項。我用了下面的方法

driver.switchTo().activeElement() 
0

我也有同樣的問題,幾個小時後,我意識到瀏覽器試圖點擊頁面加載之前的元素。

所以我創建了一個睡眠解決了這個問題:

sleep(1) 

附: - 這是我真的不喜歡的解決方案。 我只是指出你的原因。 您可以做的最好的方法是檢查您遇到問題的頁面,並嘗試優化加載時間。

0

我不相信該選項的文本實際上是可見的,然後再嘗試選擇它。嘗試按值選擇。

WebElement customerType = driver.findElement(By.id("form1:customertype_input")); 
Select select = new Select(customerType); 
select.selectByValue("N"); 

雖然您可能需要實際點擊選擇器才能選擇選項。

WebElement customerType = driver.findElement(By.id("form1:customertype_input")); 
new WebDriverWait(driver, 15).until(
      ExpectedConditions.elementToBeClickable(customerType)); 
customerType.click(); 

Select select = new Select(customerType); 
select.selectByValue("N"); 
相關問題