Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload file ( picture ) with selenium, python

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.

like image 875
Filip Avatar asked Dec 29 '11 07:12

Filip


People also ask

Can we do file upload through Selenium?

We can upload files using Selenium Webdriver. This is achieved by the sendKeys method. We have to first identify the element which performs the file selection by mentioning the file path [to be uploaded].

How do you automate upload in Python?

We can upload files with Selenium using Python. This can be done with the help of the send_keys method. First, we shall identify the element which does the task of selecting the file path that has to be uploaded. This feature is only applied to elements having the type attribute set to file.

How to upload file with selenium (Python)?

How to upload file with selenium (Python)? We can upload files with Selenium using Python. This can be done with the help of the send_keys method. First, we shall identify the element which does the task of selecting the file path that has to be uploaded.

Does Selenium WebDriver detect local file in Python?

Because local file detection is enabled by default in python selenium webdriver, there is no problem in executing the same test in remote server (for example, Selenium Grid running in some other server) and locally. When tests are running in local, webdriver does nothing special and just uploads file in given path.

How to override default file upload behavior of Python Selenium WebDriver?

If you need to override the default file upload behavior of Python Selenium Webdriver, you can use one of the available file detectors from selenium.webdriver.remote.file_detector This sample is for running tests in remote and referring files from local.

Can Selenium WebDriver handle window components?

Selenium WebDriver is not capable of handling window components, but this drawback can be overcome by using tools like Sikuli, Auto IT, etc. How to Upload a File Using Selenium?


1 Answers

What I'm doing is this (make sure drv is an instance of webdriver):

drv.find_element_by_id("IdOfInputTypeFile").send_keys(os.getcwd()+"/image.png") 

and then find your submit button and click it.

like image 94
karloskar Avatar answered Oct 17 '22 03:10

karloskar