Tag: watir

如何使用watir打开浏览器?

使用我的ruby代码我想打开Tor Browser而不是Firefox,为此我尝试了这段代码 path=’C:\Tor Browser\App\tor.exe’ Selenium::WebDriver::Firefox.path = path driver = Selenium::WebDriver.for :firefox ie = Watir::Browser.new :firefox, :driver => driver 我收到了这个错误 c:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/firefox/launcher.rb:79:in `connect_until_stable’: unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055) (Selenium::WebDriver::Error::WebDriverError) from c:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/firefox/launcher.rb:37:in `block in launch’ from c:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/firefox/socket_lock.rb:20:in `locked’ from c:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/firefox/launcher.rb:32:in `launch’ from c:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/firefox/bridge.rb:24:in `initialize’ from c:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/common/driver.rb:31:in `new’ from c:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/common/driver.rb:31:in `for’ from c:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver.rb:67:in `for’ […]

如何使用watir访问标签

我正在尝试通过watir撰写电子邮件。 因此,当我尝试访问它时,它具有标记。 任何人都可以建议如何访问它? 我的系统配置 IE-8Inter code here Windows-7 我做了以下 require ‘rubygems’ require ‘watir’ @ie.text_field(:id,’:13r’).set ‘sample’ HTML CODE CSSSTYLEsheet 我试图以文本框的forms访问它,因为“role”属性的值为“textbox”。 我得到了错误:274: assert_not_readonly’ from C:/svn/ruby/lib/ruby/gems/1.8/gems/watir-1.6.7/lib/watir/input_elem ents.rb:368:in set’中的assert_not_readonly’ from C:/svn/ruby/lib/ruby/gems/1.8/gems/watir-1.6.7/lib/watir/input_elem ents.rb:368:in ‘

当存在具有相同显示文本的其他链接时,使用Watir单击特定链接

所以我有一张桌子看起来就像那里有书籍清单,在第一栏中有两个链接,查看和删除,每本书。 我希望能够使用Watir找到具有指定书名的行,然后单击该书的该视图按钮。 这是我到目前为止所拥有的 And /^click on View link of “(.*)” on the result set table$/ do |cell_name| cellButton(“submit.view”, cell_name, “”) end # # And /^click on Delete link of “(.*)” on the result set table with no_wait$/ do |cell_name| cellButton(“submit.delete”, cell_name, “no_wait”) end # # def cellButton(submit_type, s_name, s_wait_type) c_found = 0 @browser.tables do |tbl| […]

如何使用Watir在网页上添加和执行html2canvas

如何将html2canvas添加到给定的网页,执行它,然后使用Watir读取其结果? require ‘watir’ b = Watir::Browser.new :firefox b.goto “google.com” path = “/path/to/html2canvas.js” # v. 0.5.0-alpha1 h2c_payload = File.read(path) b.execute_script h2c_payload h2c_activator = %.gsub(/\s+/, ‘ ‘).strip b.execute_script h2c_activator b.execute_script “return window.canvasImgContentDecoded” => nil 在控制台中执行相同的JavaScript会导致变量(最终)被设置,然后在调用时返回。 execute_script什么不同?

如何使用Watir 6.0下载文件

我正在尝试使用新的Watir 6.0下载CSV文件。 我找到了Firefox的配置文件设置: profile = Selenium::WebDriver::Firefox::Profile.new profile[‘browser.download.folderList’] = 2 profile[‘browser.download.dir’] = path_to_download profile[‘browser.helperApps.neverAsk.saveToDisk’] = “text/csv” browser = Watir::Browser.new :firefox, :profile => profile 但Firefox 50.0不支持加载配置文件设置。 我收到此错误消息: /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.0/lib/selenium/webdriver/remote/w3c_bridge.rb:80:in `initialize’: unknown option: {:profile=>#<Selenium::WebDriver::Firefox::Profile 我还尝试了Chrome的配置文件设置: profile = Selenium::WebDriver::Chrome::Profile.new profile[‘download.prompt_for_download’] = false profile[‘download.default_directory’] = path_to_download browser = Watir::Browser.new :chrome, :profile => Profile 但文件将不会保存,文件保存对话框也不会关闭。 所以两者都不适用于新的Watir。 有没有人知道用Watir下载文件的方法?

无法使用Watir绕过不安全的证书警告

我似乎无法忽略使用带有Watir 6.2.0的Firefox驱动程序的任何证书警告。 这是意外的行为,还是我没有正确使用API​​? 示例代码 : require ‘watir’ profile = Selenium::WebDriver::Firefox::Profile.new profile.assume_untrusted_certificate_issuer = false browser = Watir::Browser.new(:firefox, :profile => profile) browser.goto ‘https://self-signed.badssl.com/ 出乎意料的结果 : /Users/bshannon/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/response.rb:69:in `assert_ok’: Selenium::WebDriver::Error::UnknownError from /Users/bshannon/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/response.rb:32:in `initialize’ from /Users/bshannon/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/http/common.rb:83:in `new’ from /Users/bshannon/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/http/common.rb:83:in `create_response’ from /Users/bshannon/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/http/default.rb:107:in `request’ from /Users/bshannon/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/http/common.rb:61:in `call’ from /Users/bshannon/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/w3c_bridge.rb:620:in `execute’ from /Users/bshannon/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/w3c_bridge.rb:126:in `get’ from /Users/bshannon/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/common/navigation.rb:32:in `to’ from /Users/bshannon/.rvm/gems/ruby-2.4.0/gems/watir-6.2.0/lib/watir/browser.rb:78:in `goto’ from /Users/bshannon/Desktop/test.rb:8:in […]

使用带有Page-Object的IE 11 x64时出现“Watir :: Exception :: NoMatchingWindowFoundException:浏览器窗口已关闭”错误

我正在使用Page-Object + Rspec在Ruby Mine 2.7.1中运行测试。 环境:Windows 7 x64,Ruby 1.9.3 p551,IE 11。 Gems: watir , rspec , bundler , page-object 当我在Chrome或Firefox中运行测试时,一切正常。 但是当我尝试在IE中运行它们时,带有正确页面的IE窗口会被打开,之后我会在主题中指定错误: “Watir::Exception::NoMatchingWindowFoundException: browser window was closed” 关键是浏览器实际上是在那一刻打开并显示正确的页面。 (参见截屏video,了解会发生什么: http : //screencast.com/t/06prRy3OMLM ) 测试结束时出现错误,并且config.after do部分未执行,因为浏览器窗口仍然打开。 执行以下代码时会发生该错误: before(:each) do visit end 好像IEDriverServer在页面打开后立即失去与IE的连接。 最令人困惑的是,在极少数情况下,一切都运行良好,在更罕见的情况下,一切都在使用最终的超时错误显着减速。 sleep 延迟没有帮助。 我尝试了不同版本的selenium-webdriver gem(它是watir gem需要的),不同版本的IEDriverServer用于x86和x64平台 – 结果是一样的。 lib/watir-classic/exceptions.rbexception描述如下: # This exception is raised if […]

watir-webdriver在保持浏览器打开的同时更改代理

我在Ruby中使用Watir-Webdriver库来检查一些页面。 我知道我可以使用代理连接 profile = Selenium::WebDriver::Firefox::Profile.new#create a new profile profile.proxy = Selenium::WebDriver::Proxy.new(#create proxy data for in the profile :http => proxyadress, :ftp => nil, :ssl => nil, :no_proxy => nil ) browser = Watir::Browser.new :firefox, :profile => profile#create a browser window with this profile browser.goto “http://www.example.com” browser.close 但是,当想要使用不同的代理多次连接到同一页面时,我必须为每个代理创建一个新的浏览器。 加载(和卸载)浏览器需要相当长的时间。 所以,我的问题: 有没有办法改变,使用ruby中的webdriver,Firefox使用代理地址连接,同时保持浏览器打开?

Selenium WebDriver将Firefox路径更改为Tor

我正在尝试更改ruby中的webdriver来打开一个浏览器而不是默认的firefox broswer。 我正在使用以下代码,并且在运行此代码之前打开了浏览器。 path=’C:\Users\Bonnnie\Downloads\Tor Browser\App\tor.exe’ Selenium::WebDriver::Firefox.path = path driver = Selenium::WebDriver.for :firefox 我收到以下错误: unable to obtain stable firefox connection in 60 seconds 我想我可能会链接到错误的tor文件。

Ruby Watir – 尝试遍历cnn.com中的链接并单击其中的每个链接

我创建了这个方法来遍历网站中某个div中的链接。 我的方法的一个方法是收集链接将它们插入一个数组然后单击它们中的每一个。 require ‘watir-webdriver’ require ‘watir-webdriver/wait’ site = Watir::Browser.new :chrome url = “http://www.cnn.com/” site.goto url box = Array.new container = site.div(class: “column zn__column–idx-1”) wanted_links = container.links box << wanted_links wanted_links.each do |link| link.click site.goto url site.div(id: "nav__plain-header").wait_until_present end site.close 到目前为止,似乎我只能点击第一个链接,然后我收到一条错误消息,说明: unable to locate element, using {:element=>#} (Watir::Exception::UnknownObjectException) 我对ruby很新。 我感谢任何帮助。 谢谢。