0
votes

I recently inherited a Ruby test suite which is running watir-webdriver (0.6.4), and I'm in the unfortunate situation where the suite runs just fine on my colleague's machine, but several cases error out on mine. I've tried locking every version of all my gems to exactly what's on his machine to try to solve the compatibility issue, but no dice. The core error seems to be that I get the following exception originating from watir's internal `assert_valid_as_attribute' method:

(Watir::Exception::MissingWayOfFindingObjectException: invalid attribute: :css)

The originating call in my code is:

search_results.selectable_cards_plural.take(assets_selected).each { |assets| assets.fire_event ("onclick") }

search_results{...}.take returns an array of divs.

Has anyone seen this issue before? I've seen two other SO posts mentioning this issue, but neither of them seemed to address my particular issue.

I've included a portion of my gemfile.lock below, in case anyone can easily spot the compatibility issue. I'm running Ruby 2.5.0. And yes, I plan to update tests to run newer gem versions in the near future, but I want to have these legacy regression tests running in the meanwhile.

Selectors mentioned above: def search_results; @browser.div(:class, 'search-results-grid') end def selectable_cards_plural; divs(:css => 'div.p-card-hover.p-card-selectable:not(.p-card-selected)') end

The element being selected is: class="p-card-hover p-card-selectable css-g6ribn-StyledCardHover-visible-visible-visible-visible-StyledCardHover erkh22a0"

Environment info: MacOS macOS 10.14.3 (Mojave) Chrome Version 72.0.3626.121 Browser driver: @browser = Watir::Browser.new :chrome, :prefs => chrome_prefs, switches: %w[--window-size=1600,900 --ignore-certificate-errors --disable-popup-blocking --disable-translate]

Stack trace:

Asset Section: Adding # When selecting specific # from search adds assets to section
     Failure/Error: search_results.selectable_cards_plural.take(assets_selected).each { |assets| assets.fire_event ("onclick") }

     Watir::Exception::MissingWayOfFindingObjectException:
       invalid attribute: :css
     # /Users/jnguyen/.rvm/gems/ruby-2.5.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/locators/element_locator.rb:238:in `assert_valid_as_attribute'
     # /Users/jnguyen/.rvm/gems/ruby-2.5.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/locators/element_locator.rb:219:in `normalize_selector'
     # /Users/jnguyen/.rvm/gems/ruby-2.5.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/locators/element_locator.rb:198:in `block in normalized_selector'
     # /Users/jnguyen/.rvm/gems/ruby-2.5.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/locators/element_locator.rb:195:in `each'
     # /Users/jnguyen/.rvm/gems/ruby-2.5.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/locators/element_locator.rb:195:in `normalized_selector'
     # /Users/jnguyen/.rvm/gems/ruby-2.5.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/locators/element_locator.rb:98:in `find_all_by_multiple'
     # /Users/jnguyen/.rvm/gems/ruby-2.5.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/locators/element_locator.rb:46:in `locate_all'
     # /Users/jnguyen/.rvm/gems/ruby-2.5.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/element_collection.rb:96:in `elements'
     # /Users/jnguyen/.rvm/gems/ruby-2.5.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/element_collection.rb:86:in `to_a'
     # /Users/jnguyen/.rvm/gems/ruby-2.5.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/element_collection.rb:29:in `each'
     # ./lib/live_editor/assets_le.rb:37:in `take'
     # ./lib/live_editor/assets_le.rb:37:in `select_assets'
     # ./spec/smoke/live_editor/standard/asset_add_num_spec.rb:23:in `block (3 levels) in <top (required)>'

Gemfile.lock

    {...}
    commonwatir (4.0.0)
    rake (12.3.2)
    rspec (3.5.0)
      rspec-core (~> 3.5.0)
      rspec-expectations (~> 3.5.0)
      rspec-mocks (~> 3.5.0)
    rspec-core (3.5.2)
      rspec-support (~> 3.5.0)
    rspec-expectations (3.5.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.5.0)
    rspec-mocks (3.5.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.5.0)
    rspec-support (3.5.0)
    rspec_html_formatter (0.3.1)
      activesupport (>= 4.1.4)
      rouge (>= 1.6.1)
      rspec-core (>= 3.0.3)
    selenium-webdriver (2.53.4)
      childprocess (~> 0.5)
      rubyzip (~> 1.0)
      websocket (~> 1.0)
    watir (5.0.0)
      commonwatir (~> 4)
      watir-webdriver
    watir-rspec (2.0.3)
      rspec (~> 3.0)
      watir (~> 5.0)
    watir-scroll (0.1.0)
      watir-webdriver
    watir-webdriver (0.6.4)
      selenium-webdriver (>= 2.18.0)

PLATFORMS
  ruby

DEPENDENCIES
  {...}
  rake
  rspec (= 3.5.0)
  rspec-core (= 3.5.2)
  rspec_html_formatter (~> 0.3.1)
  selenium-webdriver (= 2.53.4)
  watir (~> 5.0.0)
  watir-rspec (= 2.0.3)
  watir-scroll (~> 0.1.0)
  watir-webdriver (= 0.6.4)

BUNDLED WITH
   1.17.3
1
Welcome to SO. Can you post the (minimal amount of) HTML to reproduce the issue? Given that watir-webdriver is deprecated, you should probably add the environmental info (e.g. browser, OS, browser drivers, etc). - orde
What is the locator that you are passing in? From what I recall and can tell from the code, :css locator wouldn't normally be going to assert_valid_as_attribute. - Justin Ko
Providing the full stack trace might also help us narrow down the problem. - Justin Ko
Added additional info. - John Nguyen

1 Answers

1
votes

There appears to be a version mismatch.

In v0.6.4, the following will thrown the exception:

gem 'selenium-webdriver', '=2.53.4'
gem 'watir-webdriver', '=0.6.7'

require 'watir-webdriver'

browser = Watir::Browser.new :chrome
at_exit { browser.close }
p browser.divs(:css => 'div').count
#=> `assert_valid_as_attribute': invalid attribute: :css (Watir::Exception::MissingWayOfFindingObjectException)

In this version, the only support for the :css locator was when it was by itself. The above example would include the :tag_name locator, which is the reason for the exception. You would have had to use #elements instead of divs.

This was addressed in v0.6.8 (https://github.com/watir/watir/pull/244). I would expect that your code base was created with at least v0.6.8.