- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
This feature is only applied to elements having the type attribute set to file. Also, the tagname of the element should be input. Let us investigate the html code of an element having the above properties.
Example
Code Implementation.
from selenium import webdriver driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) driver.maximize_window() driver.get("https://www.tutorialspoint.com/selenium/selenium_automat ion_practice.htm") #to identify element s = driver.find_element_by_xpath("//input[@type='file']") #file path specified with send_keys s.send_keys("C:\Users\Pictures\Logo.jpg")
Output
- Related Articles
- How to upload a file in Selenium with no text box?
- How to handle windows file upload using Selenium WebDriver?
- File Upload using Selenium WebDriver and Java Robot Class.
- How to create a file upload button with HTML?
- File Upload Example in Python
- How to upload files using Selenium Webdriver?
- How to read a text file in Selenium with python?
- How to write a text file in Selenium with python?
- Upload file with php to another php server
- How to upload a file using JSP?
- How to upload a file in Cypress?
- Downloading file to specified location with Selenium and python.
- How does selenium webdriver upload files to the browser?
- CSS Styling of File Upload Button with ::file-selector-button Selector
- How do we do a file upload using Python CGI Programming?

Advertisements