1

The following html code is resposible for uploading file and element.send_keys(absfilepath) does not work. after sending click to element it opens up the fileupload window in the os (Linux in my case) and I couldn't interact with it.

Tested with Chrome, Firefox, PhantomJS no result with any of them.

<div class="col-sm-9">
    <input value="" class="select-file-button" type="button">
</div>

which is attached to iQuery.ajaxFileUpload.js. Here is the result after file is uploaded manually:

<div class="col-sm-9">
     <div class="ajax-fileupload" style="background-image: url(&quot;/Profishop/Temp/70a569b6747041bc88da3b74871afff7/Screenshot-2017-12-12%20Telegram%20Web.png&quot;);"><input type="button" class="delete-button"></div>
 </div>

Also in the source code I found the input type="file" element but it is called by a script and it not accessible in generated page.

<div class="col-sm-9">
   <input type="file" class="afuProductImage" />
</div>

and this is the script

<script type="text/javascript">
//<![CDATA[
$(document).ready(function () {
               $(".afuProductImage").ajaxFileUpload({
               uploadHandler: "/aja/upload?id=70a569b6747041bc88da3b74871afff7&op=upload",
               deleteHandler: "/ajax/upload?op=deleteid=70a569b6747041bc88da3b74871afff7&name=",
               filePath: null,
               containerAttrs: {
               class: "ajax-fileupload"
                               },
                buttonAttrs: {
                value: ""
                 },
                });
               });//]]>
</script>

Is there a way to upload the file using selenium by sending it a javascript command?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
King110
  • 122
  • 8

1 Answers1

0

The idea is to not click the element at all costs to avoid the "File Upload" window opened.

Locate the input element with type="file" and just send the keys to it with the absolute path to the file you want to upload.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • there is `input` element with `type="file"` in source-code but when i try to access it, the error states that element class is not available. there is a `script` that calls that input. – King110 Dec 16 '17 at 08:06
  • @King110 for starters, you can try making the element visible - e.g. https://stackoverflow.com/a/25725701/771848. Is there a way for you to make the problem reproducible for us as well? May be share the URL to the webpage where you are doing it?..thanks. – alecxe Dec 16 '17 at 13:46