我正在使用HTML select
(即下拉菜單)在最初加載時沒有任何價值的網頁。它僅在其上執行一個onfocus
JS事件時加載值。請注意,這是一個GWT控制。關注並點擊使用Selenium的GWT下拉菜單
這是下拉菜單的DOM渲染。注意onfocus
事件,實際上在下拉列表中加載的值:
<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>
的問題是,在元素上的點擊是沒有得到註冊,除非該窗口是焦點。因此這些值不會被加載。
我有這個在我的代碼,這與執行不影響:
// bring the focus on the dropdown
((JavascriptExecutor) webDriver).executeScript("return document.getElementById('Field1').focus;", dropdownElement);
// click on it to load the values
dropdownElement.click();
偶試過的元素射擊事件的老辦法。沒有工作:
JavascriptLibrary javascript = new JavascriptLibrary();
javascript.callEmbeddedSelenium(webDriver, "triggerEvent", dropdownElement, "blur");
我也嘗試了一些建議,但沒有幫助:
Correct way to focus an element in Selenium WebDriver using Java
https://groups.google.com/forum/#!msg/selenium-users/jk59XG2TQk8/xbaskp9uFnQJ
可能有人建議我能做些什麼來加載值下拉?我在Firefox 47上使用Selenium 2上的Java。