user3468025 user3468025 - 6 months ago 130
Ruby Question

Ruby/Selenium/Watir-Webdriver: "path is not absolute" error for absolute path

document_name ='TestDoc'
document_path = ("/Users/Me/QA/Project/Documents/#{document_name}")

File.new ("/Users/Me/QA/Project/Documents/#{document_name}") # => File is created
filename_field.send_keys("#{document_path}")
filename_field.send_keys :tab # => To Trigger event but where error occurs


filename_field = browser.file_field(:name, 'file') declared in a module elsewhere.

As far as I can tell, I have provided an absolute path for the filename to upload the file but when the tab key is sent, an error occurs of:

Selenium::WebDriver::Error::UnknownError: unknown error: path is not absolute:


With an odd squiggly symbol in RubyMine that I've never seen before. Any ideas?

Update:

I added

puts filename_field.value
# => C:\fakepath\TestDoc


Spoke to one of the developers and she said "Browser does it to fake things out, so the filesystem isn't exposed". Not sure if that helps solve my issue or I'm SOL?

Answer

That error comes from Chromedriver, and comes from sending an incorrect path string to a file element. Since :tab is not a path, it is correctly raising an error.

You shouldn't need to send a tab; just sending the path of the file should accomplish what you need.