I am working with a HTML select
(i.e. dropdown) in a web page that initially loads with no value. It loads the values only when an onfocus
JS event is executed on it. Note that it is a GWT control.
Here is the DOM rendering of the dropdown. Note the onfocus
event that actually loads the values in the dropdown:
<select id="Field1" class="select not_disabled" onchange="clearOperators(Operator1); addOperators(Field1,Operator1); adjustInput(Field1, 1);" onfocus="loadValues(Field1);" style="width:20em;" name="Field1">
</select>
The problem is that the click on the element is not getting registered unless the window is in focus. And hence the values are not loading.
I have this in my code, and this executes with no effect:
// bring the focus on the dropdown
((JavascriptExecutor) webDriver).executeScript("return document.getElementById('Field1').focus;", dropdownElement);
// click on it to load the values
dropdownElement.click();
Even tried the old way of firing an event on the element. Did not work:
JavascriptLibrary javascript = new JavascriptLibrary();
javascript.callEmbeddedSelenium(webDriver, "triggerEvent", dropdownElement, "blur");
I also tried out some of these suggestions, but none helped:
Correct way to focus an element in Selenium WebDriver using Java
https://groups.google.com/forum/#!msg/selenium-users/jk59XG2TQk8/xbaskp9uFnQJ
Could someone suggest what I can do to load the values in the dropdown? I am using Java with Selenium 2 on Firefox 47.