0

Since the answer for my last question here we think this could help me to write a test which loops through a range of Elements using RSpec.

But realy I dont see/understand WHY following code is not working in my 'spec'

Given i write in test

source = @driver.page_source
puts source
row = source.find_elements(:xpath => "//a[contains(text(),'Details')]").length
puts row

Then it hits this error

Failure/Error: row = source.find_elements(:xpath => "//a[contains(text(),'Details')]").length

NoMethodError:
undefined method `find_elements' for #<String:0x00000003fcccd8>

that can not be?

Testracer
  • 23
  • 1
  • 4

1 Answers1

0

When you did source = @driver.page_source so now source have page source in string (String object).

find_elements works with Selenium::WebDriver object. That is your @driver(i suppose)

So just you have to do @driver.find_elements(...) and it will work.

jon snow
  • 3,062
  • 1
  • 19
  • 31