How to load file in Selenium WebDriver without input element

I have a HTML-page with the button "Upload" and id: btn-import-questions

. Element:

<button class="btn btn-success btn-sm col-lg-11" id="btn-import-questions" data-ts-file-selector="questions-import-init">  Upload&nbsp;<i class="fa fa-upload"></i></button>

      

I tried Selenium Java code like this:

driver.findElement(By.id("btn-import-questions")).sendkeys("C:/path/to/file.xlsx");

But since it's a download button and not an input-type element, the above code doesn't work.

+3


source to share


1 answer


You are doing this almost correctly, except that it should be called on input with , which is most likely invisible in your case. If so, make the element visible first: sendKeys()

type="file"



+1


source







All Articles