Marc Kubischta Marc Kubischta - 1 year ago 96
Ruby Question

How can I perform a hidden input file upload using ruby and Selenium2

I am using the ruby gem selenium-webdriver (2.39.0) to automate testing of a website.

There is a web page with a hidden input tag, which, when a user clicks a different element, is populated with the path from the system file selection dialog.

We had been able to use element.send_keys to remote upload a file for the input dialog. However, this broke on IE recently - we now get an "element not visible" error when using send_keys. After reading about the design goal of selenium 2 to only mirror user interactions I expect this to break for other browsers at some point as well.

Since the selenium 1 execute_script() method does not seem to be available in this gem, I can't modify the input tag to be visible.

I assume others have solved this - how can I perform the file upload?

Answer Source

The same method exist on that version of selenium-webdriver gem

driver.execute_script("document.getElementById('hidden').value = #{value};")

Here's the documentation:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download