Recall & Review
beginner
What is the common way to handle file uploads in Selenium with Python?
Use the
send_keys() method on the file input element to set the file path directly, simulating a user selecting a file.Click to reveal answer
beginner
Why should you avoid clicking the file upload button and then using OS dialogs in Selenium tests?
Because Selenium cannot interact with OS-level dialogs. Instead, directly set the file path on the input element to avoid flaky tests.
Click to reveal answer
beginner
How do you locate a file input element for uploading a file in Selenium?
Use reliable locators like
id, name, or CSS selectors targeting <input type='file'> elements.Click to reveal answer
intermediate
What assertion can you use after uploading a file to verify success?
Check for a confirmation message, the presence of the uploaded file name on the page, or a change in the UI indicating upload success.
Click to reveal answer
beginner
Show a simple Python Selenium code snippet to upload a file named 'example.txt' located in the project folder.
from selenium import webdriver
from selenium.webdriver.common.by import By
import os
driver = webdriver.Chrome()
driver.get('https://example.com/upload')
file_input = driver.find_element(By.ID, 'file-upload')
file_path = os.path.abspath('example.txt')
file_input.send_keys(file_path)
# Add assertions or further steps here
# driver.quit()Click to reveal answer
Which Selenium method is used to upload a file by setting the file path?
✗ Incorrect
The
send_keys() method sets the file path on the file input element to upload a file.Why should you avoid interacting with OS file dialogs in Selenium tests?
✗ Incorrect
Selenium cannot interact with OS-level dialogs, so tests become flaky if relying on them.
What type of HTML element is used for file uploads?
✗ Incorrect
File uploads use the
<input type='file'> element.Which locator strategy is best for finding a file input element?
✗ Incorrect
Using
By.ID or By.NAME is reliable for locating file input elements.After uploading a file, what is a good way to verify success?
✗ Incorrect
Verifying a confirmation message or the file name on the page confirms successful upload.
Explain how to handle file uploads in Selenium using Python, including locating the element and verifying upload success.
Think about how Selenium interacts with web elements and what happens after upload.
You got /4 concepts.
Describe why directly setting the file path on the input element is preferred over clicking and using OS dialogs in automated tests.
Consider the limitations of Selenium and test reliability.
You got /4 concepts.