@Saurav -
When you are able to select your document perfectly, anyways control/focus will be automatically shifted to your main browser window. Isn't it really?
Still if you wanted to handle from code, I will suggest to go through How to handle browser pop-up. Core concept will remain same.
If you want to use sendKeys()
to upload a file using selenium web driver, make sure that the input element is visible on the page. Once the element is visible, you should simply use below mentioned code:
driver.findElement(By.id("myUploadElement")).sendKeys("absolute path of the file");
You should not click on the browse button as it will open windows dialogue box and selenium web driver won't work.
myUploadElement
is the id of that element 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.
If sendkeys()
wont work at all, then you can also use SikuliX
to handle uploading files.
SikuliX
can be used as it automates everything that you see on the screen. It uses image recognition to identify and control GUI components.
Give a try, Hope it helps !