Recall & Review
beginner
What does the
sendKeys method do when used on a file input element in Selenium?It simulates typing the file path into the file input field, effectively selecting the file to upload without opening the file dialog.
Click to reveal answer
beginner
Why can't Selenium interact with native OS file dialogs directly?
Because Selenium controls the browser, not the operating system, so it cannot automate native dialogs like file pickers.
Click to reveal answer
beginner
Show a simple Java Selenium code snippet to upload a file using
sendKeys.WebElement uploadInput = driver.findElement(By.id("file-upload"));
uploadInput.sendKeys("C:\\Users\\User\\Documents\\file.txt");
Click to reveal answer
intermediate
What is a best practice for locating the file input element for uploading files?
Use a unique and stable locator like
id or name attributes to avoid flaky tests.Click to reveal answer
intermediate
What should you verify after uploading a file using
sendKeys in a test?Verify that the file name appears in the UI or that the upload was successful by checking for confirmation messages or file presence.
Click to reveal answer
Which Selenium method is used to upload a file by setting the file path directly?
✗ Incorrect
The sendKeys method inputs the file path into the file input element to upload the file.
Why is it better to use
id or name attributes to locate the file input element?✗ Incorrect
Unique and stable locators reduce test flakiness and improve reliability.
What happens if you try to use
click() on a file input element to upload a file in Selenium?✗ Incorrect
Clicking opens the OS dialog, which Selenium cannot automate, so tests may hang or fail.
What is a common assertion after uploading a file using sendKeys?
✗ Incorrect
Verifying the file name confirms the file was selected successfully.
Which of the following is NOT a valid locator strategy for file input elements?
✗ Incorrect
There is no By.osDialog locator; Selenium cannot locate OS dialogs.
Explain how to upload a file in Selenium using sendKeys and why this method works.
Think about how Selenium interacts with the browser elements.
You got /4 concepts.
Describe best practices for verifying a file upload in an automated test.
Focus on what you can see on the web page after upload.
You got /4 concepts.