-1

I need to automate the file upload feature in a web console and i am using selenium and java for this. I tried multiple approaches but when i click on upload button and windows explorer gets opened, it stops there. doesn't select any file...and gives error that there is no file.. I tried in firefox and chrome both but i am not able to solve this problem.

Then i also tried AutoIt tool. I downloaded it and made a script. trying to compile my script i am getting this error:

Code I'm using:

WebDriver driver = new FirefoxDriver(); 
driver.get("localhost:8080/page"); 
WebElement selectUploadApk = driver.findElement(By.id("id of upload button"));
selectUploadApk.click();
WebElement file = driver.findElement(By.xpath("//input[@type='file']")); 
file .sendKeys("path of the file");

Error: Unable to execute upx.exe to compress stub file File not found Exception

Please help

Thanx in advance

Megha

4
  • We can't help you with the code if we can't see it. Commented May 10, 2013 at 11:57
  • Hi Code which i am using looks like this WebDriver driver = new FirefoxDriver(); driver.get("localhost:8080/page"); WebElement selectUploadApk = driver.findElement(By.id("id of upload button")); selectUploadApk.click(); WebElement file = driver.findElement(By.xpath("//input[@type='file']")); file .sendKeys("path of the file"); Commented May 10, 2013 at 12:20
  • I guess you should not open the dialogue... is the //input[@type='file'] present before you click? Commented May 10, 2013 at 12:28
  • That is done to select file in windows explorer...windows explorer gets opened..but it is not selecting my file..//input[@type='file'] is given to select file..and then thru sendkeys i am entering path..i dont know whether it is correct or not..but i tried multiple approaches..still nothing working Commented May 10, 2013 at 12:31

1 Answer 1

3

You don't need to click on the field to open the dialogue box.

Opening the dialogue box is what is 'breaking' your test.

Just send the keys directly to the input element, as you are, and then click on which ever button is the 'upload' button.

  driver.findElement(By.xpath("//input[@type='file']")).sendKeys("/path/to/file");
  driver.findElement(By.id("id of upload button")).click();
Sign up to request clarification or add additional context in comments.

6 Comments

Hey thanx it is working now...atleast uploading the files..but not closing windows explorer popup.. Can anyone help me with that..
So to clarify the explorer window opens when you click the upload button? So following what I put before, it sends the path to the input element and then clicks on upload. That begins the upload as expected BUT still opens the explorer window as well?
Yes.. it will upload the file but doesn't close the windows explorer popup. which further creates problem in loop and doent go to the next file to attach and gives exception. I am trying javascript code so as to close that popup window..but its not working...
Hmm, that is unusual practice as far as I know. In all other cases for me, at least, the explorer window would only open if the user clicks on the input element or the upload element IF the path hasn't already been set. Could you provide some of the relevant HTML perhaps? Hopefully that'll give me a clue, thanks.
You need a .perform() after your .click() stackoverflow.com/questions/16597588/…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.