Error with Selenium File Upload

0 votes

While uploading a file, i'm getting this error: "Element is not reachable by keyboard" Can you help me fix it? The only thing I want to do is to attach a PDF file. But as the cusror hovers, i'm unable to find the click or upload file.

Code is:-

WebElement uploadElement = driver.findElement(By.xpath("//*[@id=\"registerproduct\"]/div/div[4]/div/div/div/div[2]/div[2]/div/div/span/label"));
uploadElement.sendKeys("C:\\Users\\Bharat\\Downloads\\apmr-auction-detail-574.pdf");

The Html is:-

<div class="col s12">
 <div class="file-field input-field">
    <div class="">
         <input id="btn_myFileInput" onchange="checkimagetype()" name="productsheet" style="display:none;" type="file">
         <span class="attached sp_head">
          <label for="btn_myFileInput" class="gray-lite attach_circle left"> 
              <i class="fa fa-paperclip small"></i>
           </label>
         <span class="sp_head">
        Attach specification sheet</span>
          <span id="fileinput-msg"></span> </span>
    </div>
 </div>

Does anyone know a remedy for this?

Mar 29, 2018 in Selenium by Shubham
• 12,030 points
591 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

In your code, you have used "WebElement" to pass the file path, and you have used the <label> tag. You should rather target the <input> tag. Besides, the <input> tag also has style attribute set to "display: none;". So, this code should do the trick:

WebElement uploadElement = driver.findElement(By.xpath("//input[@id='btn_myFileInput']"));
((JavascriptExecutor)driver).executeScript("arguments[0].removeAttribute('style')", uploadElement)
uploadElement.sendKeys("C:\\Users\\Bharat\\Downloads\\apmr-auction-detail-574.pdf");
answered Mar 29, 2018 by nsv999
• 5,030 points
Hi there, I have been trying to find the solution for the same issue for a while. @nsv99 your solution worked for me. I m so happy. Big Thank you.!
Thanks @rachel. As long as it helped :)
Thank you @nsv999 it worked fine for me

Related Questions In Selenium

0 votes
1 answer

How to handle the popup of file upload in Windows OS with WebDriver?

The value of name locator has probably ...READ MORE

answered Apr 25, 2018 in Selenium by king_kenny
• 3,590 points
1,484 views
0 votes
1 answer

How do i click on <input type=file> on any browser if i'm testing with Selenium Webdriver?

Does not matter which OS or which ...READ MORE

answered Apr 29, 2018 in Selenium by king_kenny
• 3,590 points
2,023 views
0 votes
1 answer

File Upload in Selenium Webdriver

The problem I found is excessive backslash(\) is ...READ MORE

answered May 22, 2018 in Selenium by Meci Matt
• 9,400 points
196 views
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,030 points
51 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
413 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
40 views
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.