开发者

Selenium 2.0rc3 click function too fast?

开发者 https://www.devze.com 2023-03-18 07:07 出处:网络
First off, sorry for the cryptic question. My team is currently using Selenium 2.0rc3 (with python) for testing our web app with chrome. When we used the 2.02b version of Selenium, our test passed (i

First off, sorry for the cryptic question.

My team is currently using Selenium 2.0rc3 (with python) for testing our web app with chrome. When we used the 2.02b version of Selenium, our test passed (it was a little slow and we had small hacks that we added to webdriver). After we upgraded, the test became ext开发者_StackOverflowremely fast and started failing. After debugging we found out most test failed because webdrivers click() function was not blocking() successive calls. Currently we added a sleep()/timeout of .5 secs after each click and while this solves the immediate problem, it doesn't quite achieve our main goal (which is to speed up our test)


Your problem is not really that it's clicking too fast. Just that it's clicking before that element is present. There are two ways to get round this:

  1. Wait until the element is present before clicking
  2. Increase the implicit wait time

I'm afraid I haven't used the WebDriver Python bindings. However, I can tell you how it is done in Java and hopefully you can find the Python equivalent yourself.

To wait for an element, we have in Java a class called WebDriverWait. You would write a Function which you pass to the until() method which passes only when the element exists. One way you could do that is with driver.findElements( By... ) or wrap driver.findElement( By... ) in an exception handler. The Function is polled till it returns true or the timeout specified is hit.

The second method is the preferred method for your case and in Java you can do driver.manage().timeouts().implicitlyWait( ... ).


I've tried the selenium-2 rc3 python bindings for chrome. My experience was the opposite of what you're describing - after clicking, the driver didn't know that the page was ready for it to continue. So instead of speeding up the tests, they turned out very slow (because the driver was waiting for ages). However, the firefox driver seems pretty stable - maybe you should stick with it until the chrome driver gets baked a bit more.


If the click() executes ajax calls I would suggest you to use NicelyResynchronizingAjaxController

0

精彩评论

暂无评论...
验证码 换一张
取 消