2014-01-24 47 views
0
I use to pick items from drop-down menus using `SelectElement` class in my automated tests and they worked just fine until I upgraded to Selenium 2.39 . 

ALL (!) tests that use this class fail and I get error message: `"Element is not currently visible and so may not be interacted with".` 


    I presume there is a bug in 2.39. Tested on Firefox 26.0. Anyone knows how to fix this problem? 

//Here's a piece of my HTML: 

    <select id="CodGender" class="ui-selectmenu-element" name="CodGender" data-val-required="Mandatory attribute" data-val="true" aria-disabled="false"> 
     <option value=""></option> 
     <option value="M">Male</option> 
     <option value="Z">Female</option> 
    </select> 

//and here's how I'd pick an item from the drop-down: 

    { var dropDownList = driver.FindElement(By.XPath("[@id='CodGender']")); 
     var selectElement = new SelectElement(dropDownList); 
     selectElement.SelectByText("Male"); 
    } 

這裏有一個「下拉列表」快速監視窗口結果傳遞的第二行代碼後: 顯示假 啓用真正 位置{X = -1658 Y = 791} 選擇假 尺寸{寬度= 200高度= 30} 變量名 「選擇」 文本 「」SelectElement硒2.39失敗

...這是一個爲 「selectElement」: AllSelectedOptions數= 1 IsMultiple假 選項計數= 3 [0] {OpenQA.Selenium.Firefox.FirefoxWebElement} [1] {OpenQA.Selenium.Firefox.FirefoxWebElement} [2] {OpenQA.Selenium.Firefox.FirefoxWebElement}

...然後選擇第2號的樣子: [OpenQA.Selenium.Firefox.FirefoxWebElement] {} OpenQA.Selenium.Firefox.FirefoxWebElement顯示 假 啓用真正 位置{X = -1656 Y = 851} 選擇假 大小{寬度= 197高度= 16} TagName「選項」 文本「」 ...

+0

即使通過您自己的調試,」select「也不可見,那麼用戶必須做些什麼才能看到它? – Arran

回答

0

看起來您需要顯式等待元素變爲可見或啓用。

您沒有得到NoSuchElementException這一事實表明webdriver知道該元素的存在。我會建議添加一個等待下拉菜單顯示,爲了安全起見,您還可以添加一個等待所需的文本顯示。這將阻止網絡驅動程序嘗試在該選項可用之前選擇該選項。

+0

我調試了幾次代碼,允許所有元素有足夠的時間可見。根本不工作。 – user3231962

0

這是從硒隊的詹姆斯來了一個答案: 他徹底解釋所提到的問題,以及提供一些導遊如何解決它......

「 好吧,什麼可能發生在這裏的是,您的網站正在使用某種JavaScript UI小部件框架(jQueryUI可能?),它通過使用和元素來模擬下拉菜單,但將實際數據存儲在元素中。保存實際數據的元素不可見,可能隱藏通過'ui-selectmenu-element'CSS類。

WebDriver無法與(點擊,發送鍵等)隱藏元素進行交互,完全停止。他事實上你可能操縱WebDriver以前版本中的不可見元素是一個錯誤,現在已經修復。

現在有三種選擇。首先,您可以使用UI中實際可見的UI元素來選擇適當的值。其次,您可以使用JavaScript以及您正在使用的任何JavaScript UI工具包的API,以編程方式操作「下拉」控件。對於這兩個選項中的任何一個,您將無法使用SelectElement類來操作控件,因爲您操作的元素不會是元素。最後,你可以以某種方式使實際的元素變得可見,但是你需要弄清楚你的UI小部件框架的內部工作,以便操縱元素變得可見。 「