Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
2 views
in DevOps and Agile by (29.3k points)

 how to upload a file using selenium driver, I tried to upload using send keys but its not working.

1 Answer

0 votes
by (50.2k points)

Don't click on the browse button, it will trigger an OS-level dialogue box and effectively stop your test dead. Instead, you can use:
 

driver.findElement(By.id("myUploadElement")).sendKeys("<absolutePathToMyFile>");


myUploadElement is the id of that element (button in this case) and in sendKeys, you have to specify the absolute path of the content you want to upload (Image,video etc). Selenium will do the rest for you. File uploads will only work. If the element you send a file to is an <input type="file">where the input element is visible.

Browse Categories

...