WSL + Rails + Watir + Selenium: set the value of file input

60 Views Asked by At

I am developing a Rails app using WSL/Ubuntu on a Windows 10 machine.

When I use Watir/Selenium for testing it opens a Chrome browser on my windows desktop. When I try to set the value of an input field of type "file" I get an error that the file does not exist.

The file is visible on Windows at the following path:

C:\Users\Steve\Documents\Norsemen\subs.docx

The same file is visible in Ubuntu at this path:

/mnt/c/Users/Steve/Documents/Norsemen/subs.docx

This is the html containing the input:

<form enctype="multipart/form-data" action="/matches/upload_observer_report/131073" accept-charset="UTF-8" method="post">

  <table width='100%'>
    <tr>
      <td class='align-right'>
        <strong>
          Upload Revised Expenses Form
        </strong>
      </td>
      <td class='align-left'>
        <input id="expenses_file" type="file" name="observer_report[expenses]" />
      </td>
   </tr>
   <tr>
     <td class='align-right'><input type="submit" name="commit" value="update" id="submit_1" data-disable-with="update" /></td>
   </tr>

<!-- ... -->

If I do this:

path = "/mnt/c/Users/Steve/Documents/Norsemen/subs.docx"````
browser.file_field(id: "expenses_file").set(path)

I get this error:

Selenium::WebDriver::Error::InvalidArgumentError (invalid argument: File not found : /mnt/c/Users/Steve/Documents/Norsemen/subs.docx)

If I set path to

path = "C:\\Users\\Steve\\Documents\\Norsemen\\subs.docx"
browser.file_field(id: "expenses_file").set(path)

I get a different error:

Errno::ENOENT (No such file or directory - C:\Users\Steve\Documents\Norsemen\subs.docx)

I can understand why the file needs to be visible to the browser since it's going to need to read it to perform the upload but I don't know why webdriver or Watir needs it to exist. I don't actually care what path gets set (this is just a test) but I need it to be set to something.

0

There are 0 best solutions below