I have a webpage with two dropdowns. Selecting an option in one dropdown will update the list of options in the other dropdown through a script that's triggered by the blur event. The blur event is triggered when the focus moves away from the first dropdown. This all works fine when navigating the page manually.
However, when performing the same steps through WebDriver, the blur event is never triggered, and the dropdown is thus never updated, causing my script to fail.
Here's the html for the dropdown I select first (and which has the onblur script attached to it:
<select id="newOrder:shipToAddressType" class="fieldRequired" onblur="PrimeFaces.ab({source:this,event:'blur',process:'newOrder:odShipData',update:'newO>rder:odShipData',partialSubmit:true,oncomplete:function(xhr,status,args)>{focusOnShipToZip();;}}, arguments[1]);" tabindex="47" size="1" name="newOrder:shipToAddressType">
<option selected="selected" value="125">Domestic</option>
<option value="126">International</option>
<option value="127">Military</option>
</select>
Here's what I've tried so far:
Navigating the page as I would manually I make the selection in the dropdown, then enter text in another field to move the focus away from the dropdown in order to trigger the blur event. This did not work. I also tried tabbing out of the dropdown, also no luck.
Executing javascript to trigger the blur event I know the javascript is correct, since I can successfully run it from firebug: it triggers an update of the second dropdown. However, from WebDriver it does not seem to trigger anything.
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementById('newOrder:shipToAddressType').blur()");
Any suggestions? Thanks for your help.
Edit: I tried adding 'return' to the script string. Also didn't work:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("return document.getElementById('newOrder:shipToAddressType').blur()");