In this post, we will learn how to upload a file using Selenium Webdriver in Python as well as using the SeleniumBase framework. File uploads are common use cases for the majority of websites these days, so it is important to know how to work with them.
Typically, you’ll run into two scenarios when working with file uploads. 1 — where the file input field is visible. 2 — where the file input field is hidden (most common in modern websites). Let’s take a look at an example for both of them –
Upload file on a visible input field
For this example, I will be using this website — https://the-internet.herokuapp.com/upload
As you can see in the screenshot above, the “Choose File” input field is visible. So, in this case, we can easily find the input field and send the file to that.
Upload file on a hidden input field
However, most likely, you will see in the modern websites that the file input field is hidden for styling purposes. Every website will have its own kind of implementation to hide the input field, for example — reducing the opacity to 0, setting display to none, etc…
For this example, we will be using this website — https://practice.automationbro.com/cart/
As you can see in the screenshot above, we do not see any “Choose File” input field as that is hidden behind the “Select File” button.
The key thing to notice here is the
add js code part where I am removing the hidden class to enable our input field and then uploading the file.
Check out the video below to learn how to effectively upload file in Selenium Python –
📧 Subscribe to my mailing list to get access to more content like this
👍 Follow automationbro on Twitter for the latest updates
I love coffees! And, if this post helped you out and you would like to support my work, you can do that by clicking on the button below and buying me a cup of coffee -
You can also support me by liking and sharing this content.
Thanks for reading!