Selenium onChange不工作 [英] Selenium onChange not working
问题描述
我尝试过一些事情来尝试使用Selenium从下拉菜单中选择一个onchange事件,其中没有一个是有效的。
I have tried a number of things to try and get Selenium to pick up an 'onchange' event from a drop down menu, none of which has worked.
违规的HTML是:
<select onchange="doOpperation(this.options[this.selectedIndex]); this.selectedIndex = 0;" name="opps_ondemand" id="opps_ondemand">
<option value="none" id="ondemand">Mark as...</option>
<option cmd="blah1" value="add">Something</option>
<option cmd="blah2" value="remove">None</option>
</select>
我已经看到Selenium IDE没有记录一些*事件,所以这将是明智的使用fireEvent():
I have read that Selenium IDE doesn't record some on* events, and so it would be wise to use fireEvent():
$this->click("opps_ondemand");
$this->select("opps_ondemand", "label=Mark as...");
$this->click("//option[@value='add']");
sleep(3);
$this->fireEvent("//select[@id='opps_ondemand']", "change");
但是,这不起作用(有或没有fireEvent)。我也尝试使用
However, this does not work (with or without the fireEvent). I have also tried using
$this->fireEvent("locator", "click");
而不是
$this->click("locator");
但这没有什么。
硒不抱怨这些定位器不存在,所以我假设它可以看到选择/选项元素罚款。问题似乎是onChange事件。
Selenium does not complain about these locators not existing so I am assuming it can see the select/option elements fine. The problem seems to be the onChange event.
有谁知道如何解决这个问题?
Does anyone know how to resolve this?
谢谢。 / p>
Thanks.
推荐答案
我遇到了这个问题,但在IE中(Firefox和Google Chrome对我来说可以正常工作)
I encountered exactly this problem, but in IE only (Firefox and Google Chrome works fine for me)
我发现使用JavaScript通过Selenium的 runScript
手动强制更新解决方案。有些方法可以在这里找到:
I found the solution to be manually forcing the update using JavaScript through Selenium's runScript
. Some ways to do that can be found here:
例如,如果我在我的网页上有jQuery,我会这样做:
For example, if I have jQuery in my Web page, I would do this:
$this->select('IDOfSelectElement', '*some label*');
$this->runScript("$('#IDOfSelectElement').trigger('change')");
这篇关于Selenium onChange不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!