Skip to content Skip to sidebar Skip to footer

Unable To Upload File Using Selenium Web Driver

I am trying to upload file using selenium web driver by the following code: WebDriver driver = new HtmlUnitDriver(); // And now use this to visit login page

Solution 1:

Your code looks correct to me. I assume that the file exists on your system. You also provide the absolute path of the file to upload which is also right. To me it looks like, the form is not getting submitted correctly. So I would recommend to use submit(); instead of click();

 WebElement commitButton=driver.findElement(By.name("commit"));
 commitButton.submit();

From your comment, it seems like submit(); works for FirefoxDriver() and doesn't for HtmlUnitDriver. I noticed that your HtmlUnitDriver doesn't have Javascript enabled. From the documentation here, try below

HtmlUnitDriverdriver=newHtmlUnitDriver();
driver.setJavascriptEnabled(true);

or

HtmlUnitDriverdriver=newHtmlUnitDriver(true);

Also make sure you have the latest Selenium library.

Post a Comment for "Unable To Upload File Using Selenium Web Driver"