java - Selenium:为什么 click() 的行为不像在 Firefox 中那样?

标签 java junit selenium selenium-rc

我有一个带有 id 的链接:

<a href="#" onclick="return false();" id="lol">

在我的测试中:

selenium.click("lol"); //when running the test, the click will just end up selecting the item, not firing off the frameworks javascript

这和注册点击一样!有一个 javascript 是一个复杂框架的一部分,它会导致一个 div 弹出。这适用于 Firefox。

但这确实可以解决问题:

selenium.click("lol"); //when running the test, the click will just end up selecting the item, not firing off the frameworks javascript
selenium.keyPress("lol", "\\13"); //press enter key, since the click ended up selecting it

修复确实有效。然而,这是怎么回事?似乎 selenium.click() != [实际浏览器点击事件]。任何人都可以帮助阐明这些内部运作方式吗?

最佳答案

Selenium 有时不能准确地模拟对 javascript hrefs 的点击。也许这里是同样的问题。快速解决方法是结合使用 selenium 的 mousedown 和 mouseup 事件。您还可以考虑使用 selenium.fireEvent("lol","click");。尝试这些后返回。

关于java - Selenium:为什么 click() 的行为不像在 Firefox 中那样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3102766/

相关文章:

java - 如何在运行时加载 .class 文件以与 JUnitCore.runclasses() 一起使用

python - Selenium send_keys 没有响应

java - 将 JSON 文件中的 JSON 数组解析为 Java ArrayList

java - 针对外部模式文件验证 JSON 模式是否符合 Jackson

spring - @NotTransactional替代

java - 如何使用 spring 和mockito 获取被测对象的字段

python - 在Windows7上安装Selenium/Python Bindings 2.35.0

selenium - 使用 'Press Key' 关键字按回车键

JavaFX:仅在更新标签时不在应用程序线程中?

java - 使用比较器对链表进行排序