Karthik Ravichandran
Karthik Ravichandran

Reputation: 1283

In selenium test cases, how to select the file in input type file

I have to select the file from input type= "file" using selenium test cases. So I have followed the below way.

browser.element(By.id('fileupload')).click();       

By adding this line , popup window has been opened. From that window i need to select document.docx file from the D:\files\document.docx location.

But i dont know how to open the corresponding location and select the file programaticaly in javascript.

Upvotes: 0

Views: 76

Answers (2)

undetected Selenium
undetected Selenium

Reputation: 193098

As per your question if the file upload element includes input type= "file" the most easiest and efficient way is :

browser.element(By.id('fileupload')).sendKeys("D:\\files\\document.docx");

Upvotes: 1

Anand
Anand

Reputation: 1939

Check if this works for your:

browser.element(By.id('fileupload')).sendKeys(filepath);   

Normally when its an input it accepts a direct filepath.

Upvotes: 3

Related Questions