2

I'm trying to automate file upload on a modern web page that uses some fancy drag&drop upload panel on top of the old <input type="file">. The element is still on the page but Selenium can't use it - I get the famous

"Element is not currently visible and so may not be interacted with"

error. I think I've got two options:

  1. Make the element somehow visible - but calling jQuery(...).show() on it doesn't help, I'm not quite sure why F12 tools report the element as visible but Selenium still thinks it isn't (and, truth to be told, I can't see the file field either, F12 tools just highlight a rectangular area on the page)
  2. Set the value of <input type="file"> via JavaScript but I get all sorts of security errors (tried Firefox and Chrome).

What can I do about it? Ideally, there would be a way to force Selenium to carry out the action no matter if the element is visible or not but I don't think it's possible, is it?

Borek Bernard
  • 50,745
  • 59
  • 165
  • 240
  • As my knowledge, if selenium said it's invisible, mean it's invisible with current indicator. You could switch to a more specific indicator to ensure you point to a visible element. I suggest you should waitUntilelementExist, then perform upload file – Nguyen Vu Hoang Dec 23 '14 at 05:44
  • The file upload element never becomes visible on this page - it just some kind of fallback or I don't know but by default, it is overlayed by the modern, AJAX-y uploader. – Borek Bernard Dec 23 '14 at 12:41

1 Answers1

0

Use an alternative method to hide the file input, such as:

  • absolute positioning offscreen

  • absolute positioning + clip:rect

then it will work.

References

Community
  • 1
  • 1
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
  • I do not really control how the page is constructed. Ideally I would be able to call `$selenium->byId('file-input')->forceClick()` or something like that. – Borek Bernard Dec 29 '14 at 09:58
  • @borek There's another tool called [Sikuli](https://github.com/RaiMan/SikuliX-2014) and a demo project called [Sikuli on Selenium](https://github.com/mubbashir/Sikuli-on-Selenium) which does something like this. – Paul Sweatte Dec 29 '14 at 16:42