jQuery in Action, 3rd edition
The moose likes Testing and the fly likes File upload using selenium (selenium-java-2.15.0.jar) not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "File upload using selenium (selenium-java-2.15.0.jar) not working" Watch "File upload using selenium (selenium-java-2.15.0.jar) not working" New topic

File upload using selenium (selenium-java-2.15.0.jar) not working

Soumyajit Hazra
Ranch Hand

Joined: Jun 26, 2007
Posts: 136
Hi Ranchers,
I wrote a java code to connect to a site and after navigating to few pages try to upload a file.
But whenever I am trying to upload a file it gives the message "File upload failed. Please close the file and try again" in the driver.getPageSource() output . Is it like the website not allowing the file upload and sends this message back or its some selenium restriction on file upload.
Few important points- 1. The actual website only runs in IE
2. When I created my own dummy code in servlet/jsp for file upload and use the same selenium code then it worked
Please help

Java Programmer | SCJP 1.5 | SCWCD 1.4
Brian Burress
Ranch Hand

Joined: Jun 30, 2003
Posts: 128

Which WebDriver implementation are you using (i.e. the headless HTML Driver or the InternetExplorer driver?)

The way you describe using the getSource leads me to believe you are using the HTML driver and as such can not see for yourself what is happening. I am just beginning to work with the InternetExplorerDriver implementation itself (I typically use firefox), but what I can say is that most of my "debugging" of similar issues is performed by setting a breakpoint in the code right before the error or even at the beginning of the test and watching the browser as the various steps are "painted" in the UI and performed.

If everything "looks" ok when you do this, then the next step is to inspect the HTML as you are seeing in the driver window. It is possible that there is more than one element matching the "id" used and you are firing an event that does not make sense. Sometimes these buttons are activated/deactivated based on checkboxes, etc and could be hidden in multiple frames, etc. If this is the case, you may need to look at finding the element using XPath so you can put some additional qualifications on the conditions to find the element.

The fact that your dummy JSP works unfortunately does not mean much unless the dummy code renders the exact code (HTML, javascript, etc) that the target sight does and otherwise behaves the same way. One additional trick I have used is to capture the true HTML and put it into a local JSP as you describe so that I can at least test against a local copy and avoid the internet traffic but this is more of a convenience aspect than anything.
I agree. Here's the link: http://aspose.com/file-tools
subject: File upload using selenium (selenium-java-2.15.0.jar) not working
jQuery in Action, 3rd edition