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>
Hubu999
  • 73
  • 2
  • 9

1 Answers1

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);