Do you have questions ? We got the answers!

Ask a question:

0
How to upload a file on browserstack with selenium scripts?

Solved 1 Answers 502 Views
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

1
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 Jan 6 by stbadmin (4,970 points)
selected Mar 3 by stbadmin
6Comments
commented Jan 6 by Vipul Sharma (322 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]-->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>FoodNiche</title>
    <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="https://vjs.zencdn.net/5.4.4/video-js.css" rel="stylesheet">

    <!-- Google analytics -->
    <script>
        (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
              (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
        })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

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

    </script>
    <script type="text/javascript">
      _atrk_opts = { atrk_acct:"mFGjo1IW18106C", domain:"foodniche.me",dynamic: true};
      (function() { var as = document.createElement('script'); as.type = 'text/javascript'; as.async = true; as.src = "https://d31qbv1cthcecs.cloudfront.net/atrk.js"; var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(as, s); })();
    </script>
    <noscript><img src="https://d5nxst8fruw4z.cloudfront.net/atrk.gif?account=mFGjo1IW18106C" style="display:none" height="1" width="1" alt="" /></noscript>
</head>
<body>

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

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

<script type="text/javascript" src="https://js.stripe.com/v2/"></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="https://maps.googleapis.com/maps/api/js?key=AIzaSyCWhvvcHNGEYJRTwunB_5Ar9B3paqu4Tqs&libraries=places"></script>
<script src="https://vjs.zencdn.net/5.4.4/video.js"></script>
</body>
</html>
commented Jan 6 by Vipul Sharma (322 points)
Screenshot ref: http://prntscr.com/ds912k
commented Jan 6 by stbadmin (4,970 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 Jan 9 by Vipul Sharma (322 points)
Thank you sir for such a good information.
Please can you tell me, how i can use javaScript to upload the file?
commented Jan 12 by Vipul Sharma (322 points)
edited Jan 12 by Vipul Sharma
Hi Sir, i found the solution for this problem.

((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());
        Thread.sleep(2000);
        driver.findElement(By.xpath(".//*[@id='content']/div[2]/div/div[2]/div/div/form/div/div/div[3]/div[1]/input")).sendKeys("file\\path");
commented Jan 12 by stbadmin (4,970 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.

Top Contributors

  • 4970 pointsstbadmin

    34 questions 454 answers218 comments

  • 433 pointsSunilBhaskar

    41 questions 15 answers32 comments

  • 425 pointsMehedi

    36 questions 3 answers14 comments

  • 364 pointssumitkumarwatts

    0 questions 14 answers0 comments

  • 354 pointsSoft Tester

    43 questions 0 answers4 comments

  • 327 pointsKeeshaGolden

    0 questions 17 answers2 comments

  • 322 pointsVipul Sharma

    44 questions 0 answers24 comments

  • 310 pointsvysh.sharma

    25 questions 0 answers0 comments

  • 267 pointsOnkar_Nimje

    33 questions 15 answers15 comments

  • 258 pointsVanitha

    26 questions 0 answers6 comments

...