Tag: selenium webdriver

如何使用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’ […]

紧跟在h3之后的文本框的CSS选择器路径,带有文本“公司名称”

下面是我的HTML Company Name Full Company Legal Name Company Phone Federal Tax / Employer ID (EIN) 由于所有文本字段和各个父div 类属性的类值相同,我需要填充这些文本字段而不使用nth-of-type。 我已经完成了创建一个CSS选择器的工作,该选择器应该指向 Full Company Legal Name 之后的文本框。 h3:包含(^公司名称$)+ div>输入 但我的Capybara脚本没有认识到上述方法并抛出以下错误。 annotateInvalidSelectorError_’:给定的选择器h3:包含(^ Company Name $)+ div> input无效或不导致WebElement。 发生以下错误:(Selenium :: WebDriver :: Error :: InvalidSelectorError)InvalidSelectorError:指定了无效或非法的选择器 任何人都可以提供符合我要求的CSS吗? 此致,Avinash Duggirala

如何使用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绕过不安全的证书警告

我似乎无法忽略使用带有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 […]

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文件。

如何在无头Chrome上使用Selenium Webdriver?

我正在学习使用Selenium来做基本的事情,例如截取屏幕,抓取和测试,并希望将它与无头Chrome一起使用,Chrome现在从Chrome 59开始就是稳定的。 我已经能够使用’selenium-webdriver’gem和chromedriver截取屏幕截图,但不是无头。 这是我正在运行的ruby脚本,它在开始初始化驱动程序后挂起 require ‘rubygems’ require ‘selenium-webdriver’ Selenium::WebDriver.logger.level = :debug p ‘initializing driver’ driver = Selenium::WebDriver.for :chrome, switches: %w[–headless –disable-gpu –screenshot –hide-scrollbars] p ‘navigating to Google’ driver.navigate.to “http://google.com” driver.save_screenshot(“./screen.png”) driver.quit 和日志的输出: :> ruby rubytest.rb “initializing driver” 2017-06-07 15:55:43 DEBUG Selenium Executing Process [“/Users/name/Documents/scrapings/python/env/bin/chromedriver”, “–port=9515”] 2017-06-07 15:55:43 DEBUG Selenium polling for socket on [“127.0.0.1”, 9515] […]

使用Selenium WebDriver启用/禁用javascript

出于某种原因,我要为Firefox禁用javascript(手动,我们通过以下步骤提到http://support.mozilla.org/en-US/kb/javascript-settings-for-interactive-web-pages#w_enabling – 并禁用-javascript )。 如何通过Selenium WebDriver使用Ruby实现这一目标?

如何基于capybara中的元素发送JavaScript

我希望在Capybara做类似的事情: browser.execute_script(“arguments[0].setAttribute(‘value’, ‘value’)”, element) 上面的行是在selenium / ruby​​上运行的,但是使用带有capybara的execute_script只需要1个参数(脚本),因此我无法定义我希望执行脚本的元素……任何想法?

如何根据行中的文本单击表中的链接

使用page-object和watir-webdriver如何根据行文本单击表中的链接,如下所示: 该表包含3行,其中第一列中包含名称,右侧列中包含相应的“详细信息”链接: 仪表板….详情 示例……细节 等等。 ALL THE DETAILS: ….soon DASHBOARD: —> Based on this text ….some element Details —> I should able click this link

如何访问我在Selenium Webdriver中添加的Firefox扩展?

我知道您可以加载现有的Firefox配置文件,或者在selenium-webdriver gem中使用Ruby Bindings创建一个,如下所述: http://code.google.com/p/selenium/wiki/RubyBindings 然后使用add_extension向实例添加任意数量的Firefox扩展,但那又是什么? 我正在使用的扩展窗口在测试期间不会出现。 我该如何使用扩展程序? 有没有办法在驱动程序打开Firefox时默认打开扩展程序? 这是我正在使用的代码: #!/usr/bin/env ruby require “rubygems” require “selenium-webdriver” default_profile = Selenium::WebDriver::Firefox::Profile.from_name “default” default_profile.add_extension(“/Users/******/Library/Application Support/Firef\ ox/Profiles/wvon3h99.default/extensions/{9c51bd27-6ed8-4000-a2bf-36cb95c0c947}.\ xpi”) driver = Selenium::WebDriver.for(:firefox, :profile => default_profile) driver.navigate.to “http://google.com” element = driver.find_element(:name, ‘q’) element.send_keys “Hello WebDriver!” element.submit puts driver.title driver.quit