Bird
0
0

You want to upload a file using Selenium but the input element is hidden (display:none). What is the best practice to handle this situation?

hard📝 Application Q9 of 15
Selenium Java - Handling Form Elements
You want to upload a file using Selenium but the input element is hidden (display:none). What is the best practice to handle this situation?
AUse Actions class to click the hidden input
BDirectly call sendKeys on the hidden input element
CThrow an exception and skip the upload
DUse JavaScript to remove the hidden attribute and then sendKeys
Step-by-Step Solution
Solution:
  1. Step 1: Recognize that sendKeys fails on hidden elements

    sendKeys requires visible and interactable elements; hidden inputs cause errors.
  2. Step 2: Use JavaScript to make input visible

    Removing hidden styles via JavaScript allows sendKeys to work properly.
  3. Final Answer:

    Use JavaScript to remove the hidden attribute and then sendKeys -> Option D
  4. Quick Check:

    Make hidden input visible before sendKeys [OK]
Quick Trick: Make hidden input visible with JS before sendKeys [OK]
Common Mistakes:
MISTAKES
  • Trying sendKeys on hidden input directly
  • Using Actions class to click hidden input
  • Skipping upload without fix

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes