0

I'm trying to upload a file using Selenium Webdriver and Java. I use sendKeys method on WebElement and this not working for me. I tried a lot of solution for example from this File Upload using Selenium WebDriver and Java Robot Class and also nothing.

Code with button:

<div class="button_to_upload" xpath="1">
 <span tabindex="0" class="upload" role="button">
 <input type="file" style="display: none;">
 <button class="any_class_button" type="button" style="min-width: 50px;">
 <span class="icon">
 </span><span style="">Upload something</span>
 </button>
 </span>
</div>
asked Jun 30, 2020 at 10:06

1 Answer 1

1

The easiest way to upload file using WebDriver is to set the text value of to file path. Something like this:

driver.findElement(By.ByXpath("//input[@type = 'file']")).sendKeys(filePath);
answered Jun 30, 2020 at 11:27

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.