Consulting

Results 1 to 5 of 5

Thread: Login to web page not working

  1. #1

    Unhappy Login to web page not working

    hi all,

    im trying to login into a web page but the code i normally use doesn't work. I tried different methods i found on this site and many others, with no success.

    please help

    my code

    [vba]
    Dim htmlDoc As HTMLDocument, oBrowser As InternetExplorer
    Dim oHTML_Element As IHTMLElement, sURL As String
    Sub SetTargets()
    sURL = "http://tesco.activemanagement.com/home/frameset.aspx"
    Set oBrowser = New InternetExplorer
    oBrowser.Visible = True
    oBrowser.navigate sURL
    Do
    Loop Until oBrowser.ReadyState = READYSTATE_COMPLETE

    Set htmlDoc = oBrowser.Document
    '##############################
    '######### all the below fail ##########
    '##############################
    htmlDoc.forms("frmInput").elements("UserName").Value = "hello"
    htmlDoc.frmInput.UserName.Value = "hello"
    htmlDoc.all.frmInput("UserName").Value = "hello"
    htmlDoc.all.Item("UserName").Value = "hello"
    htmlDoc.forms(0).all("UserName").Value = "hello"
    htmlDoc.getElementById("UserName").Value = "hello"
    htmlDoc.all.UserName.Value = "hello"

    End Sub
    [/vba]

    i either get 'Object variable or with block variable not set' or 'Object doesn't support this property or method'.

    Can someone please point me in the right direction

    source code for page

    HTML Code:
    <!
     
    DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
     
    <
     
    html>
     
     
    <head>
     
     
    <META http-equiv="Content-Type" content="text/html; charset=utf-8">
     
     
    <META name="ATMSVersionNumber" content="">
     
     
    <title>Isotrak</title>
     
     
    <link rel="stylesheet" type="text/css" href="../cssv3/default.css">
     
     
    <style type="text/css">
     
     
    #page {
     
     
    width: 370px;
     
                        }
     
     
    </style><script language="javascript">
     
     
     
     
     
     
    var contentHeightAdjustment = 0;
     
     
    //The timeline svg is a constant now so we just have to
     
     
    //take 486 off the avilable page height to work out the height of the scroller
     
     
    var scrollDifferenceFromAvailableHeight = 500;
     
     
    function fnSetContentSize() {
     
     
    var el_scroller = document.getElementById('scroller');
     
     
    var el_page = document.getElementById('page');
     
     
    var el_pageheader = document.getElementById('pageHeader');
     
     
    var el_pagebody = document.getElementById('pageBody');
     
     
    var el_pagefooter = document.getElementById('pageFooter');
     
     
    var el_map = document.getElementById('map');
     
     
    var el_ra_scroller = document.getElementById('ra_scroller');
     
     
     
     
    if (el_page != null) {
     
     
    var availableHeight = (document.all ? document.body.clientHeight : window.innerHeight) - 25;
     
     
    var requiredHeight = el_page.offsetHeight;
     
                    contentHeightAdjustment = availableHeight - requiredHeight;
     
     
     
     
    if (el_scroller != null) {
     
     
    var h_scroller = el_scroller.offsetHeight;
     
     
    if ((h_scroller + contentHeightAdjustment) > 0)
     
                        el_scroller.style.height = (h_scroller + contentHeightAdjustment) + 
    'px';
     
                    }
     
     
     
     
    //Andy Postlethwaite
     
     
    //ra_scroller is in routeanalysis
     
     
    if (el_ra_scroller != null) {
     
     
    var scrollHeight = 0;
     
     
    var el_div_timeline = document.getElementById('divTimeline');
     
     
    if (el_div_timeline != null)
     
              {
     
                scrollHeight = availableHeight - (el_div_timeline.offsetHeight + 200)
     
              }
     
     
    else
     
              {
     
                scrollHeight = availableHeight - scrollDifferenceFromAvailableHeight;
     
              }
     
     
     
     
    if(scrollHeight > 0)
     
              {
     
                el_ra_scroller.style.height = scrollHeight + 
    'px';
     
              }
     
     
     
                    }
     
     
     
     
    if (typeof(scrollerArray) == 'object') {
     
     
    // determine type of scroller array 
     
     
    // default to 'v' - scrollers are arranged vertically down the page
     
     
    // if any of the proportions are 100, set to 'h' - scrollers are arranged horizontally across the page
     
     
    var scrollerType = 'v';
     
     
    for (i = 0; i < scrollerArray.length; i += 2) {
     
     
    if (scrollerArray[i+1] == 100) {
     
                                scrollerType = 
    'h';
     
     
    break;
     
                            }
     
                        }
     
     
    if (scrollerType == 'v') {
     
     
    var total_h_userscroller = 0;
     
     
    for (i = 0; i < scrollerArray.length; i += 2) {
     
     
    var el_userscroller = document.getElementById(scrollerArray[i]);
     
     
    if (el_userscroller != null) {
     
     
    var h_userscroller = el_userscroller.offsetHeight;
     
                                    total_h_userscroller += h_userscroller;
     
                                }
     
                            }
     
     
    var avail_h_userscroller = (total_h_userscroller + contentHeightAdjustment > 0) ? total_h_userscroller + contentHeightAdjustment : 0;
     
     
    for (i = 0; i < scrollerArray.length; i += 2) {
     
     
    var el_userscroller = document.getElementById(scrollerArray[i]);
     
     
    if (el_userscroller != null) {
     
     
    var new_h_userscroller = Math.floor(avail_h_userscroller * parseInt(scrollerArray[i+1]) / 100);
     
     
    if (new_h_userscroller > 0) {
     
                                        el_userscroller.style.height = new_h_userscroller + 
    'px';
     
                                    }
     
                                }
     
                            }
     
                        }
     
     
    else {
     
     
    var max_h_userscroller = 0;
     
     
    for (i = 0; i < scrollerArray.length; i += 2) {
     
     
    var el_userscroller = document.getElementById(scrollerArray[i]);
     
     
    if (el_userscroller != null) {
     
     
    var h_userscroller = el_userscroller.offsetHeight;
     
     
    if (h_userscroller > max_h_userscroller) {
     
                                        max_h_userscroller = h_userscroller;
     
                                    }
     
                                }
     
                            }
     
     
    var avail_h_userscroller = (total_h_userscroller + contentHeightAdjustment > 0) ? total_h_userscroller + contentHeightAdjustment : 0;
     
     
    for (i = 0; i < scrollerArray.length; i += 2) {
     
     
    var el_userscroller = document.getElementById(scrollerArray[i]);
     
     
    if (el_userscroller != null) {
     
     
    if ((max_h_userscroller + contentHeightAdjustment) > 0) {
     
                                        el_userscroller.style.height = (max_h_userscroller + contentHeightAdjustment) + 
    'px';
     
                                    }
     
                                }
     
                            }
     
                        }
     
                    }
     
     
     
     
     
     
     
     
     
     
    if (el_map != null && el_page != null && el_pageheader != null && el_pagefooter != null) {
     
     
    var w_page = el_page.offsetWidth;
     
     
    var w_pagebody = (el_pagebody == null) ? 0 : el_pagebody.offsetWidth;
     
     
    var h_map = availableHeight - el_pageheader.offsetHeight - el_pagefooter.offsetHeight - 10;
     
     
    var w_map = w_page - w_pagebody - (document.all ? 5 : 25);
     
                        el_map.style.height = h_map + 
    'px';
     
                        el_map.style.width = w_map + 
    'px';
     
     
     
     
    var mapurl = '';
     
     
    var mapmode = '';
     
     
     
              loadSVG(
    'map', 'svgmap', mapurl + '?content=*.svg&w=' + w_map + '&h=' + h_map, w_map,  h_map); 
     
                    }
     
     
     
     
     
     
     
                }
     
            }
     
     
     
     
    function fnResizeContent() {
     
     
    // call resize logic twice ?!? - seems to be necessary for IE to resize reliably
     
                fnSetContentSize();
     
                fnSetContentSize();
     
            }
     
     
     
     
    function fnHideMenu() {
     
     
    if(top.frames['TitleFrame'] != null)
     
                {
     
                    top.frames[
    'TitleFrame'].navbar_hidecurrent();
     
                }
     
            }
     
     
     
     
    function fnOnKeypress() {
     
     
    if (window.event.keyCode == 13 && document.getElementById('EventCode') != null) {
     
                    window.event.keyCode = 0;
     
                    process_login()
     
                }
     
            }
     
     
     
     
     
     
    if (window.attachEvent) {
     
                window.attachEvent(
    'onload', fnSetContentSize);
     
                window.attachEvent(
    'onresize', fnResizeContent);
     
                document.attachEvent(
    'onclick', fnHideMenu);
     
     
     
     
     
                document.attachEvent(
    'onkeyup', fnOnKeypress);
     
     
     
     
     
            }
     
     
    else {
     
                window.addEventListener(
    'load', fnSetContentSize, false);
     
                window.addEventListener(
    'resize', fnSetContentSize, false);
     
                document.addEventListener(
    'click', fnHideMenu, false);
     
     
     
     
     
                document.addEventListener(
    'keyup', fnOnKeypress, false);
     
     
     
     
     
            }
     
     
     
     
     
     
    </script><script language="javascript" src="../scripts/sniffer__6_1_0B_HF11.js"></script><script language="javascript" src="../scripts/common__6_1_0B_HF11.js"></script><script language="javascript" src="../scripts/ieupdate__6_1_0B_HF11.js"></script><script language="javascript" src="../scripts/validation__6_1_0B_HF11.js"></script><script language="javascript" src="../scripts/AJAX__6_1_0B_HF11.js"></script><script language="javascript" src="../scripts/emailvalidation__6_1_0B_HF11.js"></script><script language="javascript" src="../scripts/pager__6_1_0B_HF11.js"></script><script language="javascript" src="../scripts/checkboxgroup__6_1_0B_HF11.js"></script><script language="javascript" src="../scripts/date-formatting__6_1_0B_HF11.js"></script><script language="javascript" src="../scripts/Workflow/justifytext__6_1_0B_HF11.js"></script><script language="javascript" src="../scripts/element-positioning__6_1_0B_HF11.js"></script><script language="javascript" src="../scripts/SensorObjects__6_1_0B_HF11.js"></script></head><script language="JavaScript">
     
     
    if (parent.frames.length == 0)
     
                        {
     
     
    if (window.name.indexOf("ISOPrint") == -1)
     
                            { top.location = 
    '../default.aspx'; }
     
                        }
     
     
    </script><script language="javascript" src="../scripts/md5__6_1_0B_HF11.js"></script><script Language="JavaScript">
     
     
     
     
    function body_onload() {
     
                document.frmInput.UserName.focus();
     
            }
     
     
     
     
    function process_login() {
     
     
    var n = document.frmInput.UserPassword_Input.value.length;
     
                document.frmInput.UserPassword.value = hex_md5(document.frmInput.UserPassword_Input.value);
     
                document.frmInput.UserPassword_Input.value = 
    '********************'.substr(1,n);;
     
                document.frmInput.eventCode.value = 
    'login';
     
                document.frmInput.submit();
     
            }
     
     
     
     
    </script><body onload="body_onload()">
     
     
    <iframe id="menuShim" src="javascript:false;" scrolling="no" frameborder="0" class="shim" xmlns:msxsl="urn:schemas-microsoft-com:xslt"></iframe>
     
     
    <form id="frmInput" name="frmInput" method="post" action="../home/login_put.aspx"><input type="hidden" name="eventCode" id="eventCode" value=""><input type="hidden" name="UserPassword" id="UserPassword" value=""><div id="page">
     
     
    <div id="pageHeader" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
     
     
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
     
     
    <tr>
     
     
    <td><img alt="Isotrak Portal" title="Isotrak Portal" src="../images/default/hdnIsotrakPortal_EN.gif"></td><script language="javascript">
     
                top.document.title = 
    'Isotrak Portal - Isotrak ATM';
     
     
    </script><script language="javascript">setPageNumber('5006','AMLVEW06')</script></tr>
     
     
    </table>
     
     
    </div>
     
     
    <div id="pageBody" style="text-align: center">
     
     
    <table border="0" cellpadding="0" cellspacing="0" class="separator" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
     
     
    <tr>
     
     
    <td width="13" valign="bottom"><img border="0" height="13" width="13" src="../images/default/imgHeaderDot.gif"></td>
     
     
    <td>&nbsp;<span class="custsub">Login</span></td>
     
     
    <td align="right"><span class="custsub-hilite"></span>&nbsp;</td>
     
     
    </tr>
     
     
    </table>
     
     
    <div style="margin: 0 auto; width: 210px; padding: 15px 0;">
     
     
    <table width="100%" cellpadding="0" cellspacing="0" border="0">
     
     
    <tr height="30">
     
     
    <td class="labelbold" width="80">Username</td>
     
     
    <td><input name="UserName" id="UserName" type="text" maxlength="15" style="width: 125"></td>
     
     
    </tr>
     
     
    <tr height="30">
     
     
    <td class="labelbold">Password</td>
     
     
    <td><input name="UserPassword_Input" id="UserPassword_Input" autocomplete="off" type="password" maxlength="15" style="width: 125"></td>
     
     
    </tr>
     
     
    </table>
     
     
    </div>
     
     
    </div>
     
     
    <div id="pageFooter" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
     
     
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
     
     
    <tr>
     
     
    <td>&nbsp;</td>
     
     
    <td align="right" id="pageFooterButtons">&nbsp;&nbsp;<a href="javascript:process_login()"><img border="0" alt="enter" title="enter" src="../images/default/btnEnter_EN.gif"></a></td>
     
     
    </tr>
     
     
    </table>
     
     
    </div>
     
     
    </div>
     
     
    </form>
     
     
    </body>
     
    </
     
    html>
     




    thanks

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    hi.

    this is a working example from KB for connecting to the forum:

    http://www.vbaexpress.com/kb/getarticle.php?kb_id=399
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    Quote Originally Posted by mancubus
    hi.

    this is a working example from KB for connecting to the forum:

    http://www.vbaexpress.com/kb/getarticle.php?kb_id=399
    Thanks for the reply, tried the above but with no success. I think the web page im trying to login to is built differently.

    If someone with a better understanding than me could take a look at the webpage, i would be very grateful.

  4. #4
    anyone with any ideas?

  5. #5
    The clue is in the URL - frameset.aspx - so you need to access the HTMLDocument in the correct frame element.

Posting Permissions

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