问题描述
我正在升级我的watir脚本,所以我只想对watir-webdriver等待页面加载>这个话题发表评论,但是因为我有1个rep我不能。到watir-webdriver和我在Firefox上运行的第一个测试产生:
Selenium :: WebDriver :: Error :: NoSuchElementError:Unable定位元素:{method:tag name,selector:body}
当我所做的只是登录到我的应用程序(工作正常),单击构建信息链接,并做一个:
pre $ @ browser.text
这一直发生。在阅读这里之后,我点击了之后,并在@ browser.text之前进行了一次睡眠。我的结论显然是,Firefox驱动程序不会等到页面加载完成才能尝试
- > POST session / 8607aaa2-d72d-448a-85e1-3f96a1766da1 / element
{value:body,using:tag name}
解决方案Watir WebDriver应该等到一个页面准备好了,但问题是这么多的内容是动态生成的,确实没有一个明确的每一个准备就绪的定义。
这是等待帮助器方法的地方:
找到一个你知道你期望的元素,并使用类似的东西:
require'watir-webdriver'
b = Watir :: Browser.start'bit.ly/watir-webdriver-demo'
b.select_list(:id =>'entry_1')。wait_until_present
更新:
我认为您的问题与本机事件有关。尝试禁用本地事件
profile = Selenium :: WebDriver :: Firefox :: Profile.new
profile.native_events = false
b = Watir :: Browser.new WEB_DRIVER,:profile => profile
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).
解决方案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
这篇关于为什么我必须睡觉或等待使用watir-webdriver和Firefox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!