1
//div[@id='upload_button']
driver.findElement(By.xpath("//div[@id='upload_button']")).click();
driver.findElement(By.xpath("//div[@id='upload_button']")).sendKeys("V://Images//CSV/text.csv");
  • I have a upload button in my browser
  • written a script that will click the button and send the mentioned file from given path
  • Here it is selecting the Upload button and file explorer opening
  • Not opening path, to send the csv file
asked Jul 9, 2022 at 7:16
5
  • Do you see this //input[@type='file'] xpath at least 1 time in your HTML-DOM? Commented Jul 9, 2022 at 7:22
  • yes it is exist Commented Jul 9, 2022 at 7:23
  • But not highlighting upload button Commented Jul 9, 2022 at 7:24
  • <div id="upload_button"> <label> <input id="Input" type="file" accept=".txt,.csv"> <span id="noFile">Upload CSV</span> <span class="icon icon-upload"></span> </label> </div> Commented Jul 9, 2022 at 7:26
  • Got it, it does not matter if it is highlighting or not, check out the below answer. Commented Jul 9, 2022 at 7:27

2 Answers 2

3

If //input[@type='file'] is present at least one time in the HTML-DOM, the you can directly send the keys, you do not need to

  1. Click on upload button
  2. Select file using explorer
  3. and upload the file.

This feature was introduced in one of the Selenium 3 versions.

Effective code:

driver.findElement(By.xpath("//input[@type='file']")).sendKeys("V://Images//CSV/text.csv");

I would recommend that use explicit wait for more stability.

answered Jul 9, 2022 at 7:26

Comments

0

driver.findElemnt(By.xpath("//input[@type='file'])).sendKeys(" give source file path");

answered Jul 9, 2022 at 7:46

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

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.