I am using selenium webdriver to try and emulate file uploads
I have a file input field:
<input class="upload_file_field" id="main_image_file" label="false" name="banner_image_file" type="file" />
Using this in my test results in a ElementNotVisibleError
@driver.find_element(:id, "main_image_file").send_keys "/Users/dan/Desktop/sample.jpg"
I even tried to change the visibility before trying to upload the file:
@driver.execute_script("arguments[0].style.visibility='visible'; arguments[0].style.display='block'; arguments[0].style.height='100px'; arguments[0].style.width='100px'; arguments[0].style.opacity=1; arguments[0].style.zindex=20", @driver.find_element(:id, "main_image_file"))
It still results in an ElementNotVisibleError
Any advice would be much appreciated
UPDATE
Okay, turns out that there are several conditions which can make an element hidden:
- Cannot have 0 opacity
- Must have length and width > 0
- Cannot be hidden visibility
- Display can't be none
- transform property can move elements off the page which make it not visible
My problem was with the transform property. it was a way of hiding the input field by transforming it off the page completely so I could use a nicer style button using jQuery file-upload.
After that,
@driver.find_element(:id, "main_image_file").send_keys "/Users/dan/Desktop/sample.jpg"
worked perfectly well in emulating user selection of a file