Selenium click()事件似乎并不总是被触发=>导致超时? [英] Selenium click() event seems not to be always triggered => results in timeout?

查看:51
本文介绍了Selenium click()事件似乎并不总是被触发=>导致超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我要做的:

selenium.click("link=mylink");
selenium.waitForPageToLoad(60000);

// do something, then navigate to a different page 
// (window focus is never changed in-between)

selenium.click("link=mylink");
selenium.waitForPageToLoad(60000);

链接"mylink"确实存在,对click()的首次调用始终有效.但是第二个click()有时似乎有用,有时却没有.

The link "mylink" does exist, the first invocation of click() always works. But the second click() sometimes seems to work, sometimes not.

似乎根本没有触发click()事件,因为页面甚至没有开始加载.不幸的是,这种行为是不确定的.

It looks like the click() event is not triggered at all, because the page doesn't even start to load. Unfortunately this behaviour is underterministic.

这是我已经尝试过的:

  1. 设置更长的超时时间
    =>没有帮助

  1. Set longer time timeout
    => did not help

等待加载一页后出现的元素
=>也不起作用,因为页面甚至没有开始加载

Wait for an element present after loading one page
=> doesn't work either since the page does not even start to load

现在我最终两次调用click(),所以:

For now I ended up invoking click() twice, so:

selenium.click("link=mylink");
selenium.waitForPageToLoad(60000);

// do something, then navigate to a different page 
// (window focus is never changed in-between)

selenium.click("link=mylink");
selenium.click("link=mylink");
selenium.waitForPageToLoad(60000);

这将起作用,但这不是一个很好的解决方案.我还在另一个论坛上看到有人建议写"clickAndWaitWithRetry"之类的东西:

That will work, but it's not a really nice solution. I've also seen in another forum where someone suggested to write something like a 'clickAndWaitWithRetry':

  try {
      super.click("link=mylink");
      super.waitForPageToLoad(60000);
  }
  catch (SeleniumException e) {
      super.click("link=mylink");
      super.waitForPageToLoad(60000);
  }

但是我认为这也不是一个正确的解决方案.为什么有时不触发click()事件的任何想法/解释?

But I think that is also not a proper solution.... Any ideas/explanations why the click() event is sometimes not triggered?

推荐答案

有时,Selenium看起来似乎是随机的,只是不喜欢单击某些锚标记.我不确定是什么原因引起的,但是确实会发生.在这种情况下,我发现有麻烦的链接而不是

Sometimes, seemingly randomly, Selenium just doesn't like to click certain anchor tags. I am not sure what causes it, but it happens. I find in those cases w/ a troublesome link instead of doing

selenium.click(...)

selenium.fireEvent( locator, 'click' );

正如其他人在我上面所说的那样,我特别遇到了锚标签出现的问题,如下所示:

As others have stated above me, I have specifically had issues with anchor tags that appear as follows:

<a href="javascript:...." >

这篇关于Selenium click()事件似乎并不总是被触发=&gt;导致超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆