dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: waitForElementLoad() setTimeout return value How to modify this code to return a valu

  1. #1
    Join Date
    Apr 2017
    Posts
    2

    waitForElementLoad() setTimeout return value How to modify this code to return a valu

    I am writing this login helper for a company. That will help streamline the login and all. But I am having issues with waiting for elements on the page to load and then returning success or failure with the login...

    I am trying to get this to return "Fully Logged in" or "Failed Login" It doesn't return anything.


    Code:
    var jsDidLogin = beginLogin() 
    console.log(jsDidLogin)

    Code:
    function waitUntilElementFound(element, time, callFunction) //Wait for the element to be found on the page
    {
        if (document.querySelector(element) != null) {
            return callFunction();
        }
        else {
            if (!checkForFailedLogin()) {
                setTimeout(function () {
                    waitUntilElementFound(element, time, callFunction);
                }, time);
            }
            else {
                return false;
            }
        }
    }
    
    function checkForFailedLogin() {
        if (document.querySelector("div[class='modal-body ng-scope'] h1") != null) {
            if(document.querySelector("div[class='modal-body ng-scope'] h1").innerHTML == "Login Error")
            {
              return "Failed Login";
            }
        }
        else {
            return false;
        }
    }
    
    function initialTabSelect() //Load the bank page once login is completed
    {
       document.querySelectorAll("li[class='Tab'] a")[0].click();
       return "Fully Logged In";
    }
    function initialDoNotAsk() {
        document.querySelectorAll("a[ng-click='modalCancel()']")[0].click();
        return waitUntilElementFound("li[class='Tab'] a", 1000, initialTabSelect);
    }
    function initialLogin() {
        var accountName = document.getElementById("username");
        var accountPassword = document.getElementById("password");
        var evt = document.createEvent("Events");
    
        evt.initEvent("change", true, true);
        accountName.value = "USERNAME";
        accountPassword.value = "PASSWORD";
    
        accountName.dispatchEvent(evt);
        accountPassword.dispatchEvent(evt);
    
        document.querySelectorAll("form[name='loginForm'] button.icon-login")[0].click();
    
        return waitUntilElementFound("a[ng-click='modalCancel()']", 2000, initialDoNotAsk);
    }
    
    function beginLogin() {
        return waitUntilElementFound("form[name='loginForm'] button.icon-login", 1000, initialLogin);
    }

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    4,434
    If you are helping with a helper login in tool then you wouldn't be allowing auto login because you have no idea on the user that is using the machine.

    If you use web interfaces, then use a browser that has a login feature you can then use the web browsers ability to auto complete any login form because it will be specific to that users account.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  3. #3
    Join Date
    Apr 2017
    Posts
    2
    Quote Originally Posted by \\.\ View Post
    If you are helping with a helper login in tool then you wouldn't be allowing auto login because you have no idea on the user that is using the machine.

    If you use web interfaces, then use a browser that has a login feature you can then use the web browsers ability to auto complete any login form because it will be specific to that users account.

    This is not true, the user information will be fed from a secret server we run. Obviously I could not include the code that pulls there information for that server. This is browser independent. Al they will be required to donis click a bookmark that we create that has this JS code and it will perform login.

    This comment was pointless.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles