Ruby下WebDriver的相关操作指南
显性等待: wait = Selenium::WebDriver::Wait.new(:timeout => 3) wait.until { driver.find_element(:id => "cheese").displayed? }
隐性等待: driver = Selenium::WebDriver.for :firefox driver.manage.timeouts.implicit_wait = 3 # seconds 内部超时: WebDriver在内部使用http协议与各种driver发生交互联系。默认情况下,Ruby标准库中的Net::HTTP协议使用时有60秒默认超时时间,如果你调用Driver去加载一个超过60秒时间的页面,你会看到一个来自于Net:HTTP的超时错误。你可以在启动浏览器前手动配置超时时间。 client = Selenium::WebDriver::Remote::Http::Default.new client.timeout = 120 # seconds driver = Selenium::WebDriver.for(:remote,:http_client => client) ruby webdriver 启动firefox driver时,加载firebug的扩展 在官方wiki上看到 profile = Selenium::WebDriver::Firefox::Profile.new profile.add_extension("/path/to/firebug.xpi") driver = Selenium::WebDriver.for :firefox,:profile => profile
于是乎自己尝试了下,但是呢每次都是提示我firebug.xpi找不到 今天有空倒腾了,问题解决了 profile.add_extension("/path/to/firebug.xpi") 至于“/path/to/firebug.xpi”就是firebug.xpi的存放路径了,我们可以去网上下载一个firebug.xpi(对应版本, 我的ff是14,可以使用firebug-1.10.4.xpi,最好使用非firefox浏览器下载,不然提示你直接安装到firefox) require 'selenium-webdriver' #dr = Selenium::WebDriver.for :ff profile = Selenium::WebDriver::Firefox::Profile.new profile.add_extension("path/to/firebug-1.10.4.xpi") <font color="DarkOrchid">#firefox-1.10.4.xpi存放在与脚本同级的path/to下面</font> dr = Selenium::WebDriver.for :firefox,:profile => profile dr.get "http://www.baidu.com" 这样子当我们需要查看dom结构时,我们就可以直接在打开的测试页面上调试啦,不用去新开个firefox去查看dom结构了。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |