簡體   English   中英

Selenium 2.39中的SelectElement失敗

[英]SelectElement in Selenium 2.39 fails

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");
    }

通過第二行代碼后,這是“ dropDownList”的快速監視窗口結果:顯示false啟用true位置{X = -1658 Y = 791}選定的false大小{Width = 200 Height = 30} TagName“選擇” Text“”

...這是“ selectElement”的一個:AllSelectedOptions Count = 1 IsMultiple false Options Count = 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}顯示為false啟用true位置{X = -1656 Y = 851}選擇為false大小{Width = 197高度= 16} TagName“選項”文本“” ...

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

您沒有得到NoSuchElementException的事實表明webdriver知道該元素的存在。 我建議您添加一個等待下拉列表可見的頁面,為了安全起見,您還可以添加一個等待文本顯示的隊列。 在選項可用之前,這將阻止Webdriver嘗試選擇該選項。

這是硒團隊的詹姆士(James of Selenium Team)給出的答案:他徹底解釋了所提到的問題,並提供了一些解決方法。

“好的,您的網站可能正在使用某種JavaScript UI小部件框架(也許是jQueryUI?),該框架通過使用和元素來模擬下拉菜單,但將實際數據存儲在一個元素內。實際數據不可見,可能被'ui-selectmenu-element'CSS類隱藏了。

WebDriver無法與隱藏元素交互(單擊,發送鍵等),句號停止。 可以在早期版本的WebDriver中操作不可見元素的事實是一個錯誤,現已修復。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM