Selenium combo在element_id_from上抛出错误

时间:2016-03-01 19:36:32

标签: selenium selenium-webdriver

如果我尝试使用Selenium作为我的驱动程序而不是webkit,我会收到错误。

如果设置了驱动程序,则会发生这种情况:Capybara.current_driver = :selenium_chromeCapybara.current_driver = :selenium_firefox

根调用是:click_on 'Create account'。但是,任何查找呼叫都会发生这种情况。

    TypeError:
      no implicit conversion of String into Integer
      # /Users/aaron/.rvm/gems/ruby-2.1.6/gems/selenium-webdriver-2.52.0/lib/selenium/webdriver/common/bridge_helper.rb:47:in `[]'
      # /Users/aaron/.rvm/gems/ruby-2.1.6/gems/selenium-webdriver-2.52.0/lib/selenium/webdriver/common/bridge_helper.rb:47:in `element_id_from'
      # /Users/aaron/.rvm/gems/ruby-2.1.6/gems/selenium-webdriver-2.52.0/lib/selenium/webdriver/remote/bridge.rb:606:in `block in find_elements_by'
      # /Users/aaron/.rvm/gems/ruby-2.1.6/gems/selenium-webdriver-2.52.0/lib/selenium/webdriver/remote/bridge.rb:606:in `each'
      # /Users/aaron/.rvm/gems/ruby-2.1.6/gems/selenium-webdriver-2.52.0/lib/selenium/webdriver/remote/bridge.rb:606:in `map'
      # /Users/aaron/.rvm/gems/ruby-2.1.6/gems/selenium-webdriver-2.52.0/lib/selenium/webdriver/remote/bridge.rb:606:in `find_elements_by'
      # /Users/aaron/.rvm/gems/ruby-2.1.6/gems/selenium-webdriver-2.52.0/lib/selenium/webdriver/common/search_context.rb:84:in `find_elements'
      # /Users/aaron/.rvm/gems/ruby-2.1.6/gems/capybara-2.6.2/lib/capybara/selenium/driver.rb:69:in `find_xpath'
      # /Users/aaron/.rvm/gems/ruby-2.1.6/gems/capybara-2.6.2/lib/capybara/node/base.rb:107:in `find_xpath'
      # /Users/aaron/.rvm/gems/ruby-2.1.6/gems/capybara-2.6.2/lib/capybara/query.rb:110:in `block in resolve_for'
      # /Users/aaron/.rvm/gems/ruby-2.1.6/gems/capybara-2.6.2/lib/capybara/node/base.rb:80:in `synchronize'
      # /Users/aaron/.rvm/gems/ruby-2.1.6/gems/capybara-2.6.2/lib/capybara/query.rb:106:in `resolve_for'
      # /Users/aaron/.rvm/gems/ruby-2.1.6/gems/capybara-2.6.2/lib/capybara/node/finders.rb:35:in `block in find'
      # /Users/aaron/.rvm/gems/ruby-2.1.6/gems/capybara-2.6.2/lib/capybara/node/base.rb:84:in `synchronize'
      # /Users/aaron/.rvm/gems/ruby-2.1.6/gems/capybara-2.6.2/lib/capybara/node/finders.rb:33:in `find'
      # /Users/aaron/.rvm/gems/ruby-2.1.6/gems/capybara-2.6.2/lib/capybara/node/actions.rb:13:in `click_link_or_button'
      # /Users/aaron/.rvm/gems/ruby-2.1.6/gems/capybara-2.6.2/lib/capybara/session.rb:686:in `block (2 levels) in <class:Session>'
      # /Users/aaron/.rvm/gems/ruby-2.1.6/gems/capybara-angular-0.2.3/lib/capybara/angular/dsl.rb:8:in `block (2 levels) in <module:DSL>'
      # ./spec/features/pokitdok_pdpc_spec.rb:42:in `block (3 levels) in <top (required)>'

此外,如果我用该功能替换方法调用并撬开它,看起来传递了错误的对象类型:

[6] pry(#<Selenium::WebDriver::Chrome::Bridge>)> ids.map{|id| puts id.inspect; Element.new self, (id['ELEMENT'] or id['element-6066-11e4-a52e-4f735466cecf'])}
["acceptSslCerts", true]
TypeError: no implicit conversion of String into Integer
  from (pry):6:in `[]'

Capybara版本:2.6.2 Selenium Webdriver版本:2.52.0

驱动程序定义:

Capybara.register_driver :selenium_chrome do |app|
  Capybara::Selenium::Driver.new(app, :browser => :chrome)
end

Capybara.register_driver :selenium_firefox do |app|
  Capybara::Selenium::Driver.new(app, :browser => :firefox)
end

浏览器版本   Chrome:48.0.2564.109(64位)   Firefox:44.0.2

Selenium 2.52.0应该足以覆盖它们。

代码:

require "spec_helper"

describe "Pokitdok PDPC", type: :feature, js: true do
  let!(:payer) { FactoryGirl.create(:payer, :pokitdok, name: 'Mock Payer') }
  let!(:clinic_population_group) { FactoryGirl.create(:clinic_population_group, population_group: payer, public_name: payer.name) }
  let(:user) do
    {
      first_name: 'Eligible', #Look at PokitdokMock
      last_name: 'Patient', #Look at PokitdokMock
    }
  end

  before :each do
    Capybara.current_driver = :selenium_chrome
    visit '/'
  end

  context 'clinic' do
    let(:clinic) { clinic_population_group.clinic }

    before :each do
      stub_production_environment
      PokitdokMock.load_webmocks
    end
    it 'registers a PDPC payer on accurate data' do
      click_on 'Create account'
    end
  end
end

Gemfile.lock的

capybara (2.6.2)
  addressable
  mime-types (>= 1.16)
  nokogiri (>= 1.3.3)
  rack (>= 1.0.0)
  rack-test (>= 0.5.4)
  xpath (~> 2.0)
capybara-angular (0.2.3)
  capybara (>= 2.5.0)
capybara-firebug (2.1.0)
  capybara (>= 1.0, < 3.0)
  selenium-webdriver
capybara-screenshot (1.0.11)
  capybara (>= 1.0, < 3)
  launchy
capybara-webkit (1.8.0)
  capybara (>= 2.3.0, < 2.7.0)
  json
chromedriver-helper (1.0.0)
  archive-zip (~> 0.7.0)
  nokogiri (~> 1.6)
rspec (3.4.0)
  rspec-core (~> 3.4.0)
  rspec-expectations (~> 3.4.0)
  rspec-mocks (~> 3.4.0)
rspec-core (3.4.3)
  rspec-support (~> 3.4.0)
rspec-expectations (3.4.0)
  diff-lcs (>= 1.2.0, < 2.0)
  rspec-support (~> 3.4.0)
rspec-mocks (3.4.1)
  diff-lcs (>= 1.2.0, < 2.0)
  rspec-support (~> 3.4.0)
rspec-rails (3.4.2)
  actionpack (>= 3.0, < 4.3)
  activesupport (>= 3.0, < 4.3)
  railties (>= 3.0, < 4.3)
  rspec-core (~> 3.4.0)
  rspec-expectations (~> 3.4.0)
  rspec-mocks (~> 3.4.0)
  rspec-support (~> 3.4.0)
rspec-support (3.4.1)
selenium-webdriver (2.52.0)
  childprocess (~> 0.5)
  multi_json (~> 1.0)
  rubyzip (~> 1.0)
  websocket (~> 1.0)

更新

此功能发生错误:

def element_id_from(id)
  id['ELEMENT'] or id['element-6066-11e4-a52e-4f735466cecf']
end

传入的ID是:

{"cssSelectorsEnabled"=>true, "browserName"=>"firefox", "handlesAlerts"=>true, "javascriptEnabled"=>true, "nativeEvents"=>false, "platform"=>"Darwin", "rotatable"=>false, "takesScreenshot"=>true, "version"=>"44.0.2", "webStorageEnabled"=>true, "applicationCacheEnabled"=>true, "databaseEnabled"=>true, "locationContextEnabled"=>true, "acceptSslCerts"=>true}

该值来自Selenium::WebDriver::Remote::Http::Common#call

request verb, url, headers, payload

带值

#Not passed in as a hash, just did it for printing purposes
{
  verb: post
  url: http://127.0.0.1:7055/hub/session/3c3f8527-5ef5-8b42-b5e4-c46bfdfb4b78/elements
  headers: {"Accept"=>"application/json", "Content-Type"=>"application/json; charset=utf-8", "Content-Length"=>"646"}
  payload: {"using":"xpath","value":".//a[./@href][(((./@id = 'Create account' or normalize-space(string(.)) = 'Create account') or ./@title = 'Create account') or .//img[./@alt = 'Create account'])] | .//input[./@type = 'submit' or ./@type = 'reset' or ./@type = 'image' or ./@type = 'button'][((./@id = 'Create account' or ./@value = 'Create account') or ./@title = 'Create account')] | .//input[./@type = 'image'][./@alt = 'Create account'] | .//button[(((./@id = 'Create account' or ./@value = 'Create account') or normalize-space(string(.)) = 'Create account') or ./@title = 'Create account')] | .//input[./@type = 'image'][./@alt = 'Create account']"}
}

0 个答案:

没有答案