0
0
Selenium Javatesting~10 mins

File upload (sendKeys to input) in Selenium Java - Interactive Code Practice

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

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

Selenium Java
WebElement uploadInput = driver.findElement(By.id("fileUpload"));
uploadInput.[1]("C:/Users/Example/file.txt");
Drag options to blanks, or click blank then click option'
Aclick
BgetText
CsendKeys
Dsubmit
Attempts:
3 left
💡 Hint
Common Mistakes
Using click() instead of sendKeys() to upload a file.
Trying to use getText() which only reads text, not uploads files.
2fill in blank
medium

Complete the code to locate the file input element by its name attribute.

Selenium Java
WebElement uploadInput = driver.findElement(By.[1]("uploadFile"));
Drag options to blanks, or click blank then click option'
Aid
BclassName
CtagName
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.id when the element does not have an id attribute.
Using By.className or By.tagName which do not match the element uniquely.
3fill in blank
hard

Fix the error in the code to correctly upload a file using sendKeys.

Selenium Java
driver.findElement(By.id("fileInput")).[1]("/path/to/file.pdf");
Drag options to blanks, or click blank then click option'
AsendKeys
BgetAttribute
Cclick
Dclear
Attempts:
3 left
💡 Hint
Common Mistakes
Using click() which only clicks the element but does not upload.
Using getAttribute() which reads attributes but does not upload.
4fill in blank
hard

Fill both blanks to locate the file input by CSS selector and upload the file.

Selenium Java
WebElement fileInput = driver.findElement(By.[1]("[2]"));
fileInput.sendKeys("C:/files/test.png");
Drag options to blanks, or click blank then click option'
AcssSelector
Bxpath
C#fileUpload
D.upload-input
Attempts:
3 left
💡 Hint
Common Mistakes
Using xpath locator but providing a CSS selector string.
Using class selector when the element has an id.
5fill in blank
hard

Fill all three blanks to find the file input by XPath, clear it, and upload a file.

Selenium Java
WebElement input = driver.findElement(By.[1]("[2]"));
input.[3]();
input.sendKeys("/home/user/image.jpg");
Drag options to blanks, or click blank then click option'
Axpath
B//input[@type='file']
Cclear
Dclick
Attempts:
3 left
💡 Hint
Common Mistakes
Using click() instead of clear() before sendKeys.
Using incorrect XPath expression.