why must I sleep or wait using watir-webdriver and firefox?

落爺英雄遲暮 提交于 2019-12-06 04:47:25

问题


Well i wanted to comment on watir-webdriver wait for page load>this topic but since i have 1 rep I cannot.

I'm upgrading my watir scripts to watir-webdriver and the first test i ran on Firefox yielded:

Selenium::WebDriver::Error::NoSuchElementError: Unable to locate element: {"method":"tag name","selector":"body"}

when all I was doing was logging into my app (which worked fine), clicking the Build Info link, and doing a:

@browser.text

This happened consistently. After reading on here, I put a sleep after the click and before the @browser.text and it worked. My conclusion is obviously that the Firefox driver is not waiting until the page is loaded before trying the

-> POST session/8607aaa2-d72d-448a-85e1-3f96a1766da1/element
{"value":"body","using":"tag name"}

So my question is is this an isolated incident (calling @browser.body, which is not an entirely typical call) or am I going to have to use waits? It seems the whole beauty of watir is lost if I cannot expect the driver to wait until the browser is in a ready state. Also, is there a dev google group or something like that for watir-webdriver? I have the feeling I'm going to see more and more issues (several with IE9). I'll probably also ask on Alister's blog (which rocks, btw).


回答1:


Watir-WebDriver should wait until a page is ready, but the problem is so much content is dynamically generated, there really isn't a every a clear definition of ready.

This is where the waiting helper methods shine: http://watirwebdriver.com/waiting/

Find an element you know you expect, and use something like:

require 'watir-webdriver'
b = Watir::Browser.start 'bit.ly/watir-webdriver-demo'
b.select_list(:id => 'entry_1').wait_until_present

Update:

I think your problem is native events related. Try disabling native events

profile = Selenium::WebDriver::Firefox::Profile.new
profile.native_events = false
b = Watir::Browser.new WEB_DRIVER, :profile => profile


来源:https://stackoverflow.com/questions/7424645/why-must-i-sleep-or-wait-using-watir-webdriver-and-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!