The code
$b.button(:text, "Choose File").click
Has two problems (assuming your filepicker is the same as that on the inkfilepicker demo page):
- The Choose File button is in an iframe. When it comes to frames, you need to explicitly tell Watir about them.
- The Choose File is not a regular button; it is the button for a file field (). These are accessed from Watir using the
file_field
method. There is no support for just clicking the button. Instead, there is aset
method that will click the button, select a file to upload and close the window.
Assuming the filepicker in your application is the same as the one on the inkfilepicker demo page, you can do the following:
require 'watir-webdriver'
browser = Watir::Browser.new :firefox
# File to upload
file = 'C:\Users\user\Desktop\stuff.jpeg'
# Go to the demo page, which has a file uploader
browser.goto 'https://www.inkfilepicker.com/demos/'
# Click the button that opens the file uploader
browser.button(:class => 'zip-open-button').click
# Wait for the dialog to be displayed
browser.div(:id => 'filepicker_dialog_container').wait_until_present
# Set the file
browser.frame(:id => 'filepicker_dialog').file_field(:id => 'fileUploadInput').set(file)