I'm trying to automate uploading a file to an HTML filepicker using watir / watir-webdriver in Ruby like so:
@browser.form(:action => '/submit').file_fields[0].set "/myfile.txt"
But this throws the following errors which are similar when using different browsers:
SAFARI (initialized with @browser = Watir::Browser.new :safari
)
Selenium::WebDriver::Error::InvalidElementStateError: Element is not currently interactable and may not be manipulated
FIREFOX: (initialized with @browser = Watir::Browser.new :firefox
)
Selenium::WebDriver::Error::ElementNotVisibleError: Element is not currently visible and so may not be interacted with
I've been able to get this working before but now it seems to be not working. There are multiple file_fields
on the page, but in fact none of them are visible:
@browser.file_fields.map{|x| x.visible?}
=> [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false]
I don't understand why these aren't visible since I've never had this problem before. Is there a way to force them to be visible or another technique I can use?
Versions:
watir-5.0.0
watir-webdriver-0.8.0
ruby 2.1.2p95
display:none
property (and a unique id), you can do something like this:b.execute_script("document.getElementById('YOUR_ID_HERE').style.display='block';")
. – orde<input type="file" id="file-upload" class="upload" capture accept="txt">
Its computed styles are:-webkit-font-smoothing: antialiased; cursor: pointer; display: block; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 65px; font-style: normal; font-variant: normal; font-weight: normal; height: 374px; left: 0px; line-height: normal; opacity: 1; position: absolute; top: 0px; width: 300px; z-index: 3;
I used@browser.execute_script
successfully, but in ruby,visible?
remains false and I am unable to interact with the element in Watir. – CraexIt