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>

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.