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?

2
  • I couldn't interact with it What did you try? Commented Dec 16, 2017 at 5:23
  • actually couldn't find a way to access the select file open window API, I no idea how to do it. there are some guides for windows OS but nothing on linux Commented Dec 16, 2017 at 7:02

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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 for starters, you can try making the element visible - e.g. 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.

Your Answer

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.