can anyone let me know how to upload a file using selenium with java code. Please tell me the code or process.

Views: 6209

Replies to This Discussion

Get the xpath of upload text field thru firebug addon. Then add manual path of the file in the code. Then selenium.click('upload'). Hope this will resolve your problem

Hi Tarnnum,

 

See the image above and Let me know the solution for this type of problems.

 

Thanks & Regards

Tulsi

Dear Tulsi,

Please follow below sample to upload the your attachments.

selenium.type("browse", "C:\\zohotestautomation\\resources\\recruit\\candidateZip.xls");

 

Hope, this will help you.

 

Note: this is for window users.

 

Regards

Marichamy,

 

Hi Marichamy,

 

See the image above and Let me know the solution for this type of problems.

 

Thanks & Regards

Tulsi

Hi tulasiram,

 

Following steps may help u in uploading the file, replace browse and upload buttons with "element id" or "value" or "xpath of that button/link".

 

selenium.click("browse button");
selenium.waitForPageToLoad("max time to load in milliseconds");
selenium.type("upload field ID", "c:\\path of file to be uploaded from system, including filename and extension");
selenium.click("Upload button");

 

-Sachin

Hi Sachin,

 

See the image above and Let me know the solution for this type of problems.

 

Thanks & Regards

Tulsi

hi tulsi,

 

Either u click on the browse button or the textbox, the post condition will be the upload file window.

Hence u can use any of them.

 

Usually user will not be able to manually add any text into the upload text field, it always opens the upload file window.

 

If you are able to identify the new upload window using the tool, u should not have problem in uploading a file else use selenium IDE and record your flow.

Its too much easy just on the selenium record when you are uploading something after that stop recording and change to source view from Table view and see the source. And use the same command everytime when you are uploading.

 

Thanks,

Snehasish

http://istqbdumps.blogspot.com/

Hi Snehasish,

 

See the image above and Let me know the solution for this type of problems.

 

Thanks & Regards

Tulsi

Try selenium IDE.Just record one instance.And then go to the source and give the path from where u want to upload any file. Its so simple.

 

One Funny thing I generally upload any pics or docs using Selenium IDE.

 

Thanks & Regards,

Snehasish

http://istqbdumps.blogspot.com/

Hi All,

 

See the image above and Let me know the solution for this type of problems.

 

Thanks & Regards

Tulsi

 

selenium.click('Browse')

Select your file and then upload.

Another way, is to record your test case thru selenium IDE and check for the steps

 

RSS

© 2014   Created by Test Republic.

Badges  |  Report an Issue  |  Terms of Service