加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – Selenium:为什么click()的行为与firefox中的行为不同?

发布时间:2020-12-15 02:20:53 所属栏目:Java 来源:网络整理
导读:我有一个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 这不会点击相同的点击! ja
我有一个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,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”);.尝试这些时还原.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读