简体   繁体   中英

Clicking Links automatically when page is loaded in Javascript

I'm new to javascript and I'm working on a program that would automatically access information on a website. Currently, the program automatically logs into the site I'm testing on (ATT), but after the Log in occurs, I can't seem to find a way to get the program to open any links on the next page. It seems like once the initial login portion of the program occurs, the program stops running.

As of now, when I launch the program, it logs into my account, but after the log in occurs, it takes me to a promo offers page. I've been trying to find a way to automatically click "No Thanks" by using the URL connected to the "No Thanks" link, but was unable to do so. I have since changed the program to use getElementByClassName() , but I can't seem to get that to work either. I realize that getElementByClassName() isn't the best choice because it isn't universally supported, but I can't tell if it's not working due to it not being supported or due to my screwing it up! Here is my code below:

<html>
     <head>
       <title>Test</title>
       <script>
         <!--
           function login() {
              document.form1.action="https://www.att.com/olam/loginAction.olamexecute";
              document.form1.submit();
              document.action ="https://www.att.com/olam/viewInterstitialPromo.myworld";
              document.getElementByClassName("wt_BodyFormSubmit").click();
             }


         //-->
        </script>
    </head>
    <body onLoad="login()">
        <form name="form1" method="post" action="https://www.att.com/olam/loginAction.olamexecute">
          <input type="hidden" name="wireless_num"/ value = "Username">
          <input type="hidden" name="pass"/ value = "Password">
          <input type="hidden" value="dotComLogin" name="actionEvent"/>
          <input type="hidden" name="reqURI" value="/rhwc/smu">
        </form>
   </body>
</html>

What you're trying to do isn't too well suited for vanilla JavaScript. There are testing frameworks out there that are built to do what you are looking for - specifically, mimicking the interactions a human being would have with a website.

I suggest you check out Potractor . It does something called end to end testing - in which it simulates the click through of a website by a human being.

You'll still have to work out the security issues the target domain sets, but it's a much better place to start.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM