7

Locate the input item and send the file path to download the file

 2 years ago
source link: https://www.codesd.com/item/locate-the-input-item-and-send-the-file-path-to-download-the-file.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Locate the input item and send the file path to download the file

advertisements

I am trying to upload a file using selenium web driver. The UI has an upload button which is inside a div tag. The button has a hidden textbox which is inside a span tag. I am able to locate till the span tag.

<div class="ng-scope" ng-if="showUpload" style="padding-bottom:5px;">
<div class="btn ng-binding" ng-class="class" flow-drop="" style="padding-top:30px;vertical-align:middle;width:370px;height:100px;background-color:#eee;border:1px solid #ccc" ng-style="style" flow-drag-leave="style={border:'1px solid #ccc'}" flow-drag-enter="style={border:'1px solid #007670'}" flow-prevent-drop="">Drag and Drop your files here.</div>
<span class="ng-binding" style="padding:0 20px">or</span>
<span class="btn btn-primary ng-binding" flow-attrs="{accept:'image/*,.pdf,.csv,.txt,.doc'}" flow-btn="">
<i class="icon icon-file"/>
Upload File
<input type="file" style="visibility: hidden; position: absolute; width: 1px; height: 1px;" multiple="multiple" accept="image/*,.pdf,.csv,.txt,.doc"/>
</span>
</div>

I am able to locate the input tag by firepath, but the same using java code doesnt work.

WebElement m_upload = driver.findElement(By.CssSelector("input[type='files']")); returns null. Can anyone tell me how to go about this?


try following code

//Give your file path here
  var orgFile = @"C:\Users\username\Downloads\pdf.pdf";
//get uploadfile input and send pat using SendKeys
            var uploadFile = driver.FindElement(By.CssSelector("input[type='file']"));
            uploadFile.SendKeys(orgFile);

if any issue then let me know.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK