Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I think that everybody how uses Webdriver for test automation must be aware of its great advantages for web development

But there is a huge issue if file uploading is part of your webflow. It stops being test automation. The security restriction of browsers (invoking file selection) practically makes it impossible to automate tests.

Afaik the only option has webdriver click the file upload button, sleep the thread, have developer/tester manually select the file and then do the rest of the web flow.

How to deal with this, is there a workaround for it? Because it really can't be done like this. It wouldn't make sense.

This is the only case I know of when browser security restrictions do not apply:

<script language=javascript>   

  function window.onload(){   

          document.all.attachment.focus();   

          var WshShell=new ActiveXObject("WScript.Shell")   

          WshShell.sendKeys("D:\MyFile.doc")

  }   

</script>

1 Answer

0 votes
by (62.9k points)

It's very easy for the WebDriver to deal with file uploading in test automation in IE and Firefox. It’s a simple case of finding the element and typing some text into it.

driver = webdriver.Firefox()

element = driver.find_element_by_id("fileUpload")

element.send_keys("myfile.txt")

The above example is in Python but I hope you got the gist of it!

Browse Categories

...