Join 500+ Software Testing professionals. Solve problem and get your problem solved. Register Now!

How to upload a file on browserstack with selenium scripts?

Solved 1 Answers 861 Views
0 1
I am using browserstack with selenium. but i am unable to upload any file/image on browserstack. Do let me know how i can upload a file/image on browser stack.

I am using a third party tool name 'AutoIT' on my system to upload any file/image, but it is not working on browserstack. Please help me as soon as possible.

1 Answer

Best answer

When you execute tests on browser stack, you are actually executing on a remote grid. Everything happens via JSON over HTTP protocol. So, you can you execute any executable file on their remote machine.

AutoIT executes on local machine. For remote machine, you will have to upload file via JavaScript by altering existing elements on the page.

Can you edit this question and update below things?

  • HTML source of the page.
  • Screenshot of the page.
  • And your existing code using which you are uploading the image.
answered by (151 points)
selected by
commented by (324 points)
<!DOCTYPE html>
<!--[if lt IE 7]>      <html lang="en" ng-app="fnApp" class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html lang="en" ng-app="fnApp" class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html lang="en" ng-app="fnApp" class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en" ng-app="fnApp" class="no-js"> <!--<![endif]-->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <base href="/">

    <link rel="shortcut icon" type="image/png" href="/images/favicon.png"/>
    <!-- 3rd css -->
    <link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="/wro/allLibs.css">
    <!-- Our css-->
    <link rel="stylesheet" href="/wro/all.css">
    <link href="" rel="stylesheet">

    <!-- Google analytics -->
              (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

        ga('create', 'UA-71082601-1', 'auto');
        ga('send', 'pageview');

    <script type="text/javascript">
      _atrk_opts = { atrk_acct:"mFGjo1IW18106C", domain:"",dynamic: true};
      (function() { var as = document.createElement('script'); as.type = 'text/javascript'; as.async = true; as.src = ""; var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(as, s); })();
    <noscript><img src="" style="display:none" height="1" width="1" alt="" /></noscript>

<div growl></div>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="">upgrade your browser</a> to improve your experience.</p>
<div fn-header></div>
<div fn-footer></div>

<script src="/wro/allLibs.js"></script>

<script type="text/javascript" src=""></script>
<script src="/app/app.jsp"></script>
<script src="/wro/all.js"></script>
<script type="text/javascript" src="/scripts/html2canvas.js"></script>
<script type="text/javascript" src=""></script>
<script src=""></script>
commented by (324 points)
commented by (151 points)
I see your screenshot. Usually so far we are executing this kind of test cases in local grid where we can have our own executable running. So far browser stack does not support uploading of file and execution of file in their VM. Even if you could figure out JavaScript which takes file to upload. It will be very tedious to upload file to VM. So, test case like this has to be executed on local machine or local grid.

Hope that answers your question.
commented by (324 points)
Thank you sir for such a good information.
Please can you tell me, how i can use javaScript to upload the file?
commented by (324 points)
edited by
Hi Sir, i found the solution for this problem.

((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());
commented by (151 points)
Thank you for posting your solution. You can not really use JavaScript to upload file. Uploading of file is prevented to avoid possible hacking on the computer.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.