Intellipaat Back

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

How to upload a picture on a web application with the selenium testing tool? I am using python.

I tried many things, but nothing worked.

1 Answer

0 votes
by (62.9k points)
edited by

Uploading files using Webdriver

Note: this answer applies to Selenium 2. Apparently, Selenium 3 changed the interface again.

Locally

If the file is on the same machine or a mapped network drive, this is actually really straightforward: You need to "type" the path to the file into the file upload control. Example:

driver = webdriver.Firefox() element = driver.find_element_by_id("fileUpload") element.send_keys("C:\myfile.txt")

 

Using RemoteWebDriver

In need to allow the transfer of the file from a local system to the remote system so it can be uploaded, you have to set a File Detector. Java example:

driver.setFileDetector(new LocalFileDetector()); WebElement upload = driver.findElement(By.id("myfile")); upload.sendKeys("/Users/sso/the/local/path/to/darkbulb.jpg");

 Hope this helps!

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, you should enroll yourself in industry-based Selenium online courses!

Browse Categories

...