SeleniumHQ / selenium-google-code-issue-archive

Archive, please see main selenium repo
https://github.com/seleniumhq/selenium
346 stars 194 forks source link

SelectElement class in Selenium 2.39 fails when used in drop-down #6897

Closed lukeis closed 8 years ago

lukeis commented 8 years ago

Originally reported on Google Code with ID 6897

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. 

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

Reported by prindes1@yahoo.co.uk on 2014-01-24 13:46:22

lukeis commented 8 years ago
Please provide a complete executable scenario and a sample page to reproduce the issue.

Reported by barancev on 2014-01-24 13:52:12

lukeis commented 8 years ago
Let's check the quick window results first. Can we?
As you can see in Pict 2, attribute Text of Option 2 looks empty. alhtough it shouldn't
be. Tried also other SelectElement options .SelectByValue and .SelectByIndex with the
same result.

Reported by prindes1@yahoo.co.uk on 2014-01-24 16:57:26


lukeis commented 8 years ago
You see an attribute Displayed == false. Invisible elements have empty text and you
can't interact with invisible elements. Full stop.

Reported by barancev on 2014-01-24 21:00:02

lukeis commented 8 years ago
Well, I don't intend to argue, but it's OK that the drop-down  Displayed attribute is
false since I'm calling xpath via its <select> name when putting the drop-down content
to SelectElemnt class. And that's, as far as I know, how SelectElement for drop-downs
is supposed to be used ... 

... and I want to point out that this set-up worked perfectly fine with Selenium 2.33,
the test ran on previously ... 

Reported by prindes1@yahoo.co.uk on 2014-01-27 09:17:24

lukeis commented 8 years ago
You can't work with invisible elements. First you have to perform an action that makes
the dropdown visible (click a placeholder?) and as soon as it is visible you can deal
with it.

Reported by barancev on 2014-01-27 09:32:16

lukeis commented 8 years ago
Tried to click anything to "make the dropdown visible" - obiviously didn't work. 

I've recently played with various combinations of Webdriver and Firefox versions -
my outcome is the last well working combination was Webdriver 2.35 with Firefox 25.

With that being said then:
- Webdriver 2.35 wouldn't even start the FF 26
- Anything newer than Webdriver 2.35 fails to work correctly with SelectElement class
when tested on FF 25 

Reported by prindes1@yahoo.co.uk on 2014-01-27 16:16:27

lukeis commented 8 years ago
All your cries are useless unless you provide a complete executable scenario and a sample
page to reproduce the issue.

Reported by barancev on 2014-01-27 18:18:53

lukeis commented 8 years ago
Okay, what's probably happening here is that your site is using some sort of JavaScript
UI widget framework (jQueryUI maybe?), which simulates a drop-down by use of <span>
and <a> elements, but stores the actual data inside a <select> element. The <select>
element holding the actual data is not visible, probably hidden by the 'ui-selectmenu-element'
CSS class.

WebDriver cannot interact with (click, send keys to, etc.) hidden elements, full stop.
The fact that you *could* manipulate the invisible <select> element in previous versions
of WebDriver was a bug, which has now been fixed.

You have three options now. First, you can use the UI elements actually visible in
the UI to select the appropriate values. Second, you could use JavaScript, along with
the API of whatever JavaScript UI toolkit you're using, to programmatically manipulate
the "dropdown" control. For either of these two options, you won't be able to use the
SelectElement class to manipulate the control, because the elements you're manipulating
won't be <select> elements. Finally, you could somehow cause the actual <select> element
to become visible, but you'll need to figure out the inner workings of your UI widget
framework to manipulate the <select> element to become visible.

Reported by james.h.evans.jr on 2014-01-27 19:45:42

lukeis commented 8 years ago
Thank you James. I've just checked your assumptions with the guys that actually created
the code I test. Yes, you've been perfectly right. 

I appreciate the guides you've provided. Please, consider this issue solved.

Have a nice day

Reported by prindes1@yahoo.co.uk on 2014-01-28 10:11:08

lukeis commented 8 years ago

Reported by luke.semerau on 2015-09-17 18:22:01