0
0
Selenium Pythontesting~10 mins

File upload handling in Selenium Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to locate the file input element by its ID.

Selenium Python
file_input = driver.find_element(By.[1]("upload"))
Drag options to blanks, or click blank then click option'
AID
BNAME
CCLASS_NAME
DTAG_NAME
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.NAME or other locators when the element has an ID.
2fill in blank
medium

Complete the code to upload a file by sending the file path to the input element.

Selenium Python
file_input.send_keys([1])
Drag options to blanks, or click blank then click option'
Aopen('file.txt')
Bdriver.upload("file.txt")
Cupload_file()
D"/path/to/file.txt"
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to open the file or call upload functions instead of sending the path string.
3fill in blank
hard

Fix the error in the code to correctly wait for the file input element to be visible before uploading.

Selenium Python
wait = WebDriverWait(driver, 10)
file_input = wait.until(EC.[1]((By.ID, "upload")))
Drag options to blanks, or click blank then click option'
Aelement_to_be_clickable
Bpresence_of_element_located
Cvisibility_of_element_located
Delement_to_be_selected
Attempts:
3 left
💡 Hint
Common Mistakes
Using presence_of_element_located which does not guarantee visibility.
4fill in blank
hard

Complete the code to create a dictionary comprehension that maps file names to their upload status if the file size is greater than 0.

Selenium Python
upload_status = {file: file for file in files if os.path.getsize(file) [1] 0}
Drag options to blanks, or click blank then click option'
A:
B>
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using == or < instead of > for file size check.
5fill in blank
hard

Fill all three blanks to create a test that asserts the upload success message contains the uploaded file name.

Selenium Python
assert [1] in driver.find_element(By.ID, "upload_message").[2].[3]()
Drag options to blanks, or click blank then click option'
Afile_name
Btext
Clower
Dget_attribute
Attempts:
3 left
💡 Hint
Common Mistakes
Using get_attribute instead of text, or forgetting to lowercase the text.