Fetch Roast
Fetch Roast

Reputation: 23

WebDriver Sampler script in JMeter to populate a input type "File" during file upload scenario

I have tried the below script.. but no luck..

var Import = WDS.browser.findElement(pkg.By.xpath('//input[@id=\'fileUpload\']')); Import.click(); Import.sendKeys(['D:\Spreadsheets\WL_SpreadsheetImport.xlsx']);

Error Log: 2020-05-14 14:57:29,740 ERROR c.g.j.p.w.s.WebDriverSampler: invalid argument (Session info: chrome=81.0.4044.138)

Upvotes: 0

Views: 1013

Answers (1)

Dmitri T
Dmitri T

Reputation: 168042

  1. Don't call Import.click(); otherwise system modal file upload dialog will open and it is not controllable by Selenium
  2. You need to escape the backslash with another backslash like:

    Import.sendKeys(['D:\\Spreadsheets\\WL_SpreadsheetImport.xlsx']);
    

    or just use single forward slashes:

    Import.sendKeys(['D:/Spreadsheets/WL_SpreadsheetImport.xlsx']);
    

More information:

Upvotes: 1

Related Questions