代码之家  ›  专栏  ›  技术社区  ›  Zombies

Selenium:click()为什么不像firefox那样工作?

  •  4
  • Zombies  · 技术社区  · 15 年前

    我有一个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
    

    修复确实有效。但是,这里发生了什么?好像是硒。click()!=[实际浏览器单击事件]。有谁能帮忙解释一下这些内部工作原理吗?

    2 回复  |  直到 15 年前
        1
  •  1
  •   vamyip    14 年前

    Selenium有时并不完全模拟javascript的点击hrefs。也许这是同一个问题。一个快速的解决方法是结合使用selenium的mousedown和mouseup事件。你也可以考虑使用 selenium.fireEvent("lol","click"); . 试过之后再回来。

        2
  •  0
  •   Community CDub    8 年前

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