how does selenium webdriver upload files to the browser?
Posted
by
justspamjustin
on Stack Overflow
See other posts from Stack Overflow
or by justspamjustin
Published on 2012-12-20T00:58:11Z
Indexed on
2012/12/20
5:03 UTC
Read the original article
Hit count: 148
I am a javascript/java developer and I have been trying to figure out how the selenium webdriver automation framework uploads files from the file system. It is impossible to set a file input via javascript because it is a security violation. Yet somehow webdriver is able to do this with the following command:
driver.setFileDetector(new LocalFileDetector());
WebElement upload = driver.findElement(By.id("myfile"));
upload.sendKeys("/Users/sso/the/local/path/to/darkbulb.jpg");
driver.findElement(By.id("submit")).click();
So they are setting the value by sending keys to it? I don't get it. I have looked through the source code found here: http://code.google.com/p/selenium/source/checkout I am still not able to find where they do this.
Edit: My question is not how to do this with selenium, but how did the selenium developers make this possible? How did they get around the security restrictions in javascript? How are they uploading the file?
© Stack Overflow or respective owner