0

I don't know how to click on the browse button of an inputfile using Selenium. (InputFile)

Indeed, the input part, and the browse button are part of the same WebElement, and I don't know how to split them, to be able to click on the browse button. (InputFile)

Thank you in advance.

2
  • Did you try to click directly on the input tag ? In a browser you do not need to click on "Browse", you can also click on the text zone to open the popup. The behavior should be the same in Selenium. Commented Apr 26, 2018 at 7:25
  • Verify if the element is within a iframe. Commented Apr 27, 2018 at 4:25

1 Answer 1

1

It's an input tag of type file. You can directly use the below code:

driver.findElement(By.xpath("//input[@type='file']")).sendKeys("PATH_OF_FILE_TO_UPLOAD);

Then simply click on OK

Sign up to request clarification or add additional context in comments.

4 Comments

In fact, I can't use sendKeys, I can't write anything inside the input part. But I have realized that if I double click on the input part, it opens the browse file fialog.
By using sendKeys you are passing the file location inside the input tag. So what I suggested is equivalent to click on the browse button and then select the expected file.
But I can't with selenium! I can't click on the browse button to select the image.
But, as I told you, i'll try to double click to open the browser file dialog. Thank you, you gave me this idea :)

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.