selenium selectByVisibleText不会触发更改方法

时间:2014-09-15 16:59:19

标签: selenium combobox webdriver

我使用了selectByVisibleText,但与组合框关联的on change方法没有触发。

这是组合框代码

<form id="j_idt421" class="manageUsersPickerForm ng-pristine ng-valid" style="margin: 20px 0 40px    0;" enctype="application/x-www-form-urlencoded" action="/backoffice/manage-merchant-users.xhtml" method="post" name="j_idt421">
<input type="hidden" value="j_idt421" name="j_idt421"/>
<select id="j_idt421:merchantPicker" class="floatLeft mr5" onchange="RichFaces.ajax(this,event,{"parameters"  {"cid":"14256","javax.faces.behavior.event":"change","org.richfaces.ajax.component":"j_idt421:merchantPicker"} ,"sourceId":this} )" size="1" name="j_idt421:merchantPicker"> 
<option value="-1">Select a merchant</option>
<option value="0">automerchant</option>
</select>
<input id="javax.faces.ViewState" type="hidden" autocomplete="off" value="8152201385695173409:3385672536636852427" name="javax.faces.ViewState"/>
</form>

硒代码:

Select droplist = new Select(By.xpath("//select[contains(@id, 'merchantPicker')]"));
droplist.selectByVisibleText("automerchant");

在组合框中选择值后,页面冻结并且不显示另一部分。

我正在使用chromedriver 2.10

任何人都有解决此问题的方法吗?

由于

1 个答案:

答案 0 :(得分:1)

尝试使用Javascript强制onchange事件发生,如下所示:

Select droplist = new Select(By.xpath("//select[contains(@id, 'merchantPicker')]"));
droplist.selectByVisibleText("automerchant");

WebElement ele = driver.findElement(By.xpath("//select[contains(@id, 'merchantPicker')]"));
JavascriptExecutor js= (JavascriptExecutor)driver;
js.executeScript("arguments[0].onchange()", ele);