Link to home
Start Free TrialLog in
Avatar of brotherAli
brotherAli

asked on

Selenium, help in select dojo dropdown list selection

Hi Expert guys,
I am working on automation testing using Selenium. There is drop-down of on page, when I tried to select its value it gave me error that

Element should have been "select" but was "table"

In firebug I see it as table. The drop down is created on server side and dojo translate it into table on client browser and also create hidden field which is set value when user click on drop-down(actually there is small arrow, on click of it a pop-up comes and user can select a state and that hidden field is set with selected value.

Following code was working before when dojo was not used:
comboBox = new Select(select);

But after dojo use it gives error: Element should have been "select" but was "table"

How I can select value in drop-down. Please guide me with code.
I am using Selenium 2.0, java program.
Thanks.
Eidt: At least I just want to select the value in drop down (or may be set the hidden field value set) so that submit of form will not give error.
Avatar of clockwatcher
clockwatcher

Use the executeScript method to set the dojo select's value.  

In python, it'd be:

  web_driver.execute_script("dijit.byId('<id of select field>').set('value','<value you want it set to>')")

Open in new window


Haven't used selenium under java but it should be:

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("dijit.byId('<id of select field>').set('value','<value you want it set to>')");

Open in new window

Avatar of brotherAli

ASKER

It is not working giving exception.
"my_list" is id of drop-down but when I see it in Firebug as it is translated into table I see this:
<table id="my_list" class="dijit dijitReset dijitDownArrowButton dijitSelect"  aria-haspopup="true" role="combobox" dojoattachpoint="_buttonNode,tableNode,focusNode" widgetid="my_list" aria-valuetext=" Select from list ">

Now when user click on this "select from list" a pop-up window opens and user can select a value from list .
Is that possible that I can able to click this table or text and then wait and then from popup window select a value?
Or there is hidden field with same name "my_list" but has no id, can i set its value?
Because when user clicks on text (dojo combo) and select a value from popup then the selected value is assign to this hidden field by dojo.
What dijit are you using?  Can you give us the non-firebug code?  Either the javascript that is generating the dojo object or the html if it's being generated by a dojo.parse.  

I tested my post with a dijit.form.Select and it worked.  So it should work.  It's just a matter of getting the syntax correct.  Let me know the type of dijit you're using and I'll put together a small sample test script for it.
If I see in view source in FireFox I see this:

<select aria-describedby="my_listError"  aria-required="true"  class="my-styled"  name="my_list" id="my_list">
<option value=""  > Select Color </option>
<option value="BL">Blue</option>

dojo translate it into table and send to the client. So in firebug I see a table as below:

<table id="my_list" class="dijit dijitReset dijitInline dijitLeft dijitDownArrowButton dijitSelect" cellspacing="0" cellpadding="0" aria-haspopup="true" role="combobox" dojoattachpoint="_buttonNode,tableNode,focusNode" style="-moz-user-select: none;" tabindex="0" aria-disabled="false" widgetid="my_list" aria-valuetext=" Select State ">
<tbody role="presentation">
<tr role="presentation">
<td class="dijitReset dijitStretch dijitButtonContents dijitButtonNode" role="presentation">
<span class="dijitReset dijitInline dijitButtonText" dojoattachpoint="containerNode,_popupStateNode">
<span class="dijitReset dijitInline dijitSelectLabel"> Select Color </span>
</span>
<input type="hidden" aria-hidden="true" value="" dojoattachpoint="valueNode" name="my_list">
</td>

Note: Please note that when user click on "Select color" (it is a grey background with small arrow images) then a popup window opens and user select the color value from it.


experts-exchnage code:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("dijit.byId('my_list').set('value','BL')");

Please let me know if you need more information.
One more thing, I am able now to set the hidden variable value. But that is not the actual solution. I need to click and set value of drop-down please.  Thanks.
ASKER CERTIFIED SOLUTION
Avatar of clockwatcher
clockwatcher

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thankyou very much. It is working
thank you very much for your help. You are not only expert  but nice person too. I appreciate your help and effort.
Thank you.  Glad to have been of help.  :-)