Monday 21 January 2013

How to upload file using selenium webdriver in java?


How to upload file using selenium webdriver in java?

 If you click browse button, it will open a window for uploading the file.


Already we know, Selenium web driver can handle only web based application. It unable to find the window based application. So, It can't browse the files for uploading.
Then, How we can upload the file??

The simple trick is, we need to specify the path of the file in the browse text box and click upload button

Here is the code:

driver.findElement(By.xpath("xpath of Browse_Textbox")).sendKeys("path_of_file");
driver.findElement(By.xpath("xpath of upload_file_Button")).click();

2 comments:

  1. I am not able to send path to browser text box because in my application text field and browse button in one element.

    So any idea ? How can we send path or upload a file ?

    Thanks in advance.

    ReplyDelete
    Replies
    1. Hi Ankit,

      You can use AutoIT tool for uploading the files.

      Delete