Testing / Selenium Interview questions
How do you handle file uploads in Selenium?
For a standard <input type="file"> element, Selenium can set the file path directly with sendKeys(), without needing to interact with the operating system's native file picker dialog at all.
WebElement upload = driver.findElement(By.id("resume-upload")); upload.sendKeys("/absolute/path/to/resume.pdf");
This only works if the input element is present in the DOM, even if visually hidden by CSS - sendKeys() writes to the element directly rather than simulating a real click that would open an OS dialog. If a custom-styled upload widget hides the real input entirely and it can't be targeted directly, a common workaround is using JavaScript execution (via JavascriptExecutor) to temporarily reveal the hidden input, upload to it, then let the application's own JavaScript pick up the change event.
More Related questions...