I'm writing automation for a web page using Ruby and Selenium WebDriver but have encountered a blocking issue with some of the drop downs on the site which are made using JavaScript instead of standard HTML. On these drop downs users are able to select an option from the drop down or click on it and start typing for it to filter results based on what is typed (I'm assuming the idea is these drop downs are for potentially very long lists of options).
Problem is I can't figure out a way to interact with them using WebDriver, though i have managed to get it to work in the Selenium IDE using the below code, but exporting this IDE script to Ruby doesn't work:
<tr>
<td>select</td>
<td>css=select[name=dsref]</td>
<td>demo</td>
</tr>
The WebDriver code that I am using is:
def clickOn (parameters = {})
# This will accept a locator type and name to click on
#
# EXAMPLE
#
# clickOn(
# locatorType: :link,
# locatorName: 'Home'
# )
#
# This will click on the link named 'Home'
locatorType = parameters[:locatorType]
locatorName = parameters[:locatorName]
$driver.find_element(locatorType, locatorName).click
end
clickOn(
locatorType: :xpath,
locatorName: '/html/body/form/fieldset[4]/div[2]/div/div/div/a/span'
)
I have then tried to locate the selection from the drop down in the same way using the xpath of the hidden values field, but it is not able to locate the hidden values.
The javascript that I am trying to interact with is:
<div id="tabWarehousing" class="cansee">
<div class="lineFirst">
<div class="of8">
<label for="formdsref">Warehouse</label>
<br>
<select id="sel2DZ" class="admn_dropdownmenu chzn-done" size="1" name="dsref" style="display: none;">
chosen=Chosen { form_field=select#sel2DZ.admn_dropdownmenu, options= {...}, active_field=
true
, more...}
<option selected="" value=""></option>
<option value="demo">demo</option>
<option value="demodownload">demo download</option>
</select>
<div id="sel2DZ_chzn" class="chzn-container chzn-container-single chzn-container-single- nosearch" style="width: 115px;">
<a class="chzn-single" tabindex="-1" href="javascript:void(0)"> <span>demo</span>
<div>
<b></b>
</div>
</a>
<div class="chzn-drop" style="left: -9000px; width: 113px; top: 18px;">
<div class="chzn-search">
<input type="text" autocomplete="off" style="width: 78px;">
</div>
<ul class="chzn-results">
<li id="sel2DZ_chzn_o_1" class="active-result result-selected" style="">demo</li>
<li id="sel2DZ_chzn_o_2" class="active-result" style="">demo download</li>
</ul>
</div>
</div>
</div>
Any ideas on how I can set the value of this drop down using Ruby WebDriver?