Is there any way to upload file in Google Chrome since Selenium RC "attach_file" only supports *Firefox? Any suggestion or workarounds are much appreciated.
The most basic way of uploading files in Selenium is using the sendKeys method. It is an inbuilt feature for file upload in Selenium.
You can call sendKeys() on the file control to fill the file control with file path and then submit form. With this approach, no file dialog will be shown, you just bypass the file dialog and set the file path directly in the file upload control.
If you are using Webdriver then to upload file all you need is use "sendKeys" to type the file path. You need to 'skip' the part of clicking on the browse button that opens a dialog box to select the file. A Java version that works for me looks something like below,
WebElement inputFilePath = driver.findElement(By.id("filepath"));
inputFilePath.sendKeys("/absolute/path/to/my/local/file");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With