开发者

Selenium: intermittent "element not found" issues

Every now and then my selenium tests randomly fail with an "element X not found" error message. I do a simple select by ID, eg.

click('sideBar_queryButton')

When I use the dom inspector, the element is there, so I wonder why selenium doesn't find it sometimes. When I run the same test again, it works or it breaks again, t开发者_运维百科here seems to be no reliable way of reproducing it. Even tests which are there for ages seem to randomly break and then magically work again. Inserting a few sleep statements sometimes helps but not reliably. So I wonder if I'm using it incorrectly. Has anyone else had these problems with selenium and if so, how did you fix them?


Edit: I found it to be much more reliable to put some test markers in my pages and wait for them to appear. If you use asynchronous operations which might create race conditions in your tests, inserting a test marker into your html after you finish the operation worked pretty well for me. E.g.

$('<div>').addClass("testMarker").append("OpXYZFinished").appendTo($('#content'));

That way, you can do a simple "waitForTextPresent" to see if things worked out and its much more reliable than guessing the browser's loading state. The testmarker class needs to be formatted in a way that it is not visible to the user (e.g. font color == background color).

Thanks for all your comments. After some deeper digging on the net and in our tests I finally found combining these statements instead of a simple waitForPageToLoad to be the cure for our issues:

waitForPageToLoad('')
// wait until all ajax activity has ceased. That check's jQuery's $.active
waitForCondition('selenium.browserbot.getUserWindow().$.active == 0', 5000)
// wait a second for all JS to properly initialize
pause(1000)

There is still a pause in there which is somewhat ugly, but it does the trick.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜