【问题标题】:Selenium: Why does click() not behave like it does in firefox?Selenium:为什么 click() 的行为不像在 Firefox 中那样?
【发布时间】:2010-06-23 14:56:11
【问题描述】:

我有一个带有 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() != [实际浏览器点击事件]。任何人都可以帮助阐明这些内部工作原理吗?

【问题讨论】:

标签: java junit selenium selenium-rc


【解决方案1】:

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

【讨论】:

  • 我确实试过这个。它不起作用:(哦...但也许 mousedown 和 mouseup 会起作用。
【解决方案2】:

可以在加载 javascript 之前单击浏览器中的链接。见this other question。一种解决方案是等待某些元素在 javascript 放置的页面上可见。

【讨论】:

  • 我实际上确实在等待它在页面上可见。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-12
  • 2011-10-11
  • 1970-01-01
  • 1970-01-01
  • 2020-07-15
相关资源
最近更新 更多