Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97799

Uploading file in Selenium using sendKeys() is not working

$
0
0

I am unable to upload files using sendKeys(). This is my code

driver.findElement(By.xpath(Locators.browseFlagIconBtn)).sendKeys("D:\\Images\\icons.png");

I have an input tag of type file for file upload

<input type="file" id="iconFlagFile" name="iconFile" onchange="setFlagIconFile()" value="" class=" file-input-opacity" style="position: absolute; z-index: 100; font-size: 200px; line-height: 200px; top: 0px; left: 0px; opacity: 0;">

However when I click on submit button of the form where this input field is then I am redirected to the below page:

enter image description here

Cause of this issue :

When I pass the path using sendKeys() then it correctly picks up the file that needs to be uploaded. However, the actual upload takes place when user clicks on the submit button. Now I don't know why it it searches for the file that it picked in Chrome's directory, for example: "C:\Program Files (x86)\Google\Chrome\Application\53.0.2785.116"

Obviously it will not be able to find the file.

Question: How to fix this? Let me know if I need to provide more information.


Viewing all articles
Browse latest Browse all 97799

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>