Home > Software design >  Upload a file with Chromedriver to a website that uses plupload.Uploader
Upload a file with Chromedriver to a website that uses plupload.Uploader

Time:10-02

I'm trying to upload a file to a website however the standard SendKeys method does not work because the website uses plupload.Uploader() to upload files.

Browse button:

<button type="button" id="media-browse-button" class="btn btn-primary" style="position: relative; z-index: 1;">Browse...</button>

plupload:

var media_uploader = new plupload.Uploader({"runtimes":"html5","browse_button":"media-browse-button","container":"media-container","url":"\/upload","headers":{"Accept":"application\/json"},"chunk_size":"512kb","multipart_params":{},"filters":{"mime_types":[{"title":"Audio files","extensions":"mp3,m4a"}]}});media_uploader.init();document.getElementById('media-start-upload').onclick = function() {media_uploader.start();};

I have tried:

string MediaFilePath = "file path here"
driver.FindElementByXPath("//*[@id=\"media-browse-button\"]").SendKeys(MediaFilePath);

However this just opens a browse file dialog and does not upload anything.

CodePudding user response:

If in entire webpage you have

//input[@type='file']

then SendKeys will upload the files.

string MediaFilePath = "file path here"
driver.FindElementByXPath("//input[@type='file']").SendKeys(MediaFilePath);

Note that, you should not click on upload button, this would get the job done.

  • Related