rob88
02-24-2013, 01:38 PM
Hi guys, i have been stuck on this problem for a while now and i really need some help :banghead:. I am new to VB so there is no doubt i have overlooked something quite simple.
I need to click a button on a website, below is the source code ( i have also attached this as a word document as it may be easier to see)
<head id="ctl00_Head1"><title> Enquiry Menu</title><link id="ctl00_StyleSheetLink" href="../StyleSheet/PdaStyleSheet.css" type="text/css" rel="stylesheet" /> <script language="javascript" src="../Script/Script.js"></script> <script language="javascript" src="../Script/SignaturePadScript.js"></script> <script language="javascript" src="Script/Script.js"></script> <script language="javascript" src="Script/SignaturePadScript.js"></script> <!-- need to put this reference in as it looks for scripts relative to the parent page, not the master page --> <!-- <script language="javascript" src="Script/Script.js"></script> <script language="javascript" src="Script/SignaturePadScript.js"></script> --> <script language="javascript"> var lastControl = null; /*function MasterPage_ShowErrorMessage(obj, errorHeading, errorText) { var popUpObject = document.getElementById("PopupDialogBox"); var imageObj = obj; if (imageObj != lastControl) { lastControl = imageObj; //get the position of the clicked object var coors = findPos(obj); //then add 15 px to each one so we don't cover up the exclamation mark coors[1] += 15; coors[0] += 15; popUpObject.style.top = coors[1] + 'px'; popUpObject.style.left = coors[0] + 'px'; popUpObject.style.width = 200; if (popUpObject.style.pixelLeft + popUpObject.style.pixelWidth > document.body.clientWidth) popUpObject.style.pixelLeft = event.clientX - 10 - popUpObject.style.pixelWidth; popUpObject.style.display = "block"; document.getElementById("PopupDialogBoxHeading").innerText = errorHeading; document.getElementById("PopupDialogBoxMessage").innerText = errorText; } else { lastControl = null; popUpObject.style.display = "none"; } event.cancelBubble = true; } //as the position in at which the object we're trying to render will be //relative to any parent it has with absolute positioning, we want to stop //adding to the co-ordinates at which to render the object as soon as we //hit a parent with an absolute position. function findPos(obj) { var curleft = curtop = 0; if (obj.offsetParent) { curleft = obj.offsetLeft; curtop = obj.offsetTop; while ((obj = obj.offsetParent) && (getElementStyle(obj, 'position', 'position') != 'absolute')) { curleft += obj.offsetLeft; curtop += obj.offsetTop; } } return [curleft,curtop]; }*/ //expects an element and the text representations of the style property //we care about (use both IE and CCS names so it will work if someone //uses a browser other than IE). function getElementStyle(elem, IEStyleProp, CSSStyleProp) { if (elem.currentStyle) { return elem.currentStyle[IEStyleProp]; } else if (window.getComputedStyle) { var compStyle = window.getComputedStyle(elem, ""); return compStyle.getPropertyValue(CSSStyleProp); } return ""; } function MasterPage_ShowErrorMessage(obj, errorHeading, errorText) { var popUpObject = document.getElementById("PopupDialogBox"); if (obj != lastControl) { lastControl = obj; popUpObject.style.left = event.clientX + 10; popUpObject.style.top = event.clientY + 10; popUpObject.style.width = 200; if (popUpObject.style.pixelLeft + popUpObject.style.pixelWidth > document.body.clientWidth) popUpObject.style.pixelLeft = event.clientX - 10 - popUpObject.style.pixelWidth; popUpObject.style.display = "block"; document.getElementById("PopupDialogBoxHeading").innerText = errorHeading; document.getElementById("PopupDialogBoxMessage").innerText = errorText; } else { lastControl = null; popUpObject.style.display = "none"; } event.cancelBubble = true; } function DropDownChange(selectedIndex) { document.getElementById("ctl00$DropDownListSelectedIndex").value = selectedIndex; //document.getElementById("ctl00$ctl19").disabled=true; } function TextBoxChange(value) { document.getElementById("ctl00$MessageDialogTextBoxText").value = value; } function CheckBoxChange(checked) { document.getElementById("ctl00$CheckBoxCheckedTextBox").value = checked; } </script></head><body scroll="no" onclick="CatchClick(window.event.srcElement); HidePopupIfVisible();" onload="getSignature('ctl00_PageAreaContentPlaceHolder_'); SetDefaultButton(); if (window.document.title!='Home'){SetFocus();}; AutoRefresh();" onresize="ResizeWindow(600, 800);" onkeydown="CatchKeyPress(window.event.keyCode, window.event.srcElement);"> <form name="aspnetForm" method="post" action="AccountingEnquiryMenu.aspx?RoleID=206" id="aspnetForm"><div><input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /><input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" /><input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTY0MzEyMDIwOA9kFgJmD2QWAgIDD2QWBAIBDxYCHglpbm5lcmh0bWwFIlBEJmFtcDtB IEFjY291bnRpbmcgLSBFbnF1aXJ5IE1lbnVkAgMPFgQeA3NyYwUVLi4vSW1hZ2UvbmJzbG9nbzM uZ2lmHgV0aXRsZQU+UHJvZHVjdGlvbiBFbnZpcm9ubWVudA0KQ1NQUFVJUzAyDQpCdWlsZDogNC 4wLjAuMCAoNC4wLjMzNjkuMSlkZEJJDGxYtPGALzuh0onm4Kxui0c4" /></div> <script type="text/javascript"> //<![CDATA[var theForm = document.forms['aspnetForm'];if (!theForm) { theForm = document.aspnetForm;}function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); }}//]]></script> <div> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWDALPj8D6CgKq7qvMCwLKuvL/DALwnLmMAwKwxYanBQLp6ubsBgKV7M2LCwLG1/yvDwKskqPbAQLC5OTqAwKgtMnpCwLStb6OCIGym7YlFfm4ZkOW4SRNSaIkPJcT" /></div> <div class="WrenMenuContainer"> <h1 id="ctl00_WrenMenuHeader">PD&A Accounting - Enquiry Menu</h1> <img src="../Image/nbslogo3.gif" id="ctl00_WrenMenuLogoImage" border="0" align="absMiddle" title="Production EnvironmentCSPPUIS02Build: 4.0.0.0 (4.0.3369.1)" /> <div> <ul id="ctl00_WrenMenuLinkButtonList"><li><a title="Exit the application" href="javascript:__doPostBack('ctl00$ctl01','')" style="display:inline-block;width:80px;margin-left:5px;">Exit</a></li></ul> <span id="ctl00_WrenMenuUserIdLabel"></span> </div> <div class="WrenMenuFadeStrip"></div> </div> <div class="UserMessageContainer"><span id="ctl00_MessageLabel"> </span></div> <!--<div style="padding:5px 10px 5px 10px; color:Firebrick; font-size:8pt;"><u>Summary</u> > <u>Accounting</u> > <u>Search</u> > <b>Rule Detail</b></div>--> <div style="text-align:center;"> <h3>Accounting Enquiry Main Menu</h3> <input type="submit" name="ctl00$PageAreaContentPlaceholder$ButtonNavigateToPaymentEnquiry" value="Payment Enquiry" id="ctl00_PageAreaContentPlaceholder_ButtonNavigateToPaymentEnquiry" class="Buttons" style="font-weight:bold;height:25px;width:280px;" /> <br /><br /> <input type="submit" name="ctl00$PageAreaContentPlaceholder$ButtonNavigateToExtractEnquiry" value="Extract Enquiry" id="ctl00_PageAreaContentPlaceholder_ButtonNavigateToExtractEnquiry" class="Buttons" style="font-weight:bold;height:25px;width:280px;" /> <br /><br /> <input type="submit" name="ctl00$PageAreaContentPlaceholder$ButtonNavigateToTransitEnquiry" value="Trial Balance" id="ctl00_PageAreaContentPlaceholder_ButtonNavigateToTransitEnquiry" class="Buttons" style="font-weight:bold;height:25px;width:280px;" /> <br /><br /> <input type="submit" name="ctl00$PageAreaContentPlaceholder$ButtonNavigateToSummaryEnquiry" value="Summary Enquiry" id="ctl00_PageAreaContentPlaceholder_ButtonNavigateToSummaryEnquiry" class="Buttons" style="font-weight:bold;height:25px;width:280px;" /> <br /><br /> <input type="submit" name="ctl00$PageAreaContentPlaceholder$ButtonNavigateToAccountingEnquiry" value="Accounting Enquiry" id="ctl00_PageAreaContentPlaceholder_ButtonNavigateToAccountingEnquiry" class="Buttons" style="font-weight:bold;height:25px;width:280px;" /> <br /><br /> <input type="submit" name="ctl00$PageAreaContentPlaceholder$ButtonNavigateToRuleEnquiry" value="Rule Enquiry" id="ctl00_PageAreaContentPlaceholder_ButtonNavigateToRuleEnquiry" class="Buttons" style="font-weight:bold;height:25px;width:280px;" /> <br /><br /> </div> <div id="ctl00_ButtonContainer" class="ButtonContainer"></div> <div id="PopupDialogBox" class="PopupDialogBox"> <h1 id="PopupDialogBoxHeading">Message Heading</h1> <div id="PopupDialogBoxMessage">Message text of some sort.... dah dah dahhhh...</div> </div> <input name="ctl00$DropDownListSelectedIndex" type="text" value="0" id="ctl00_DropDownListSelectedIndex" class="Invisible" /> <input name="ctl00$MessageDialogTextBoxText" type="text" id="ctl00_MessageDialogTextBoxText" class="Invisible" /> <input name="ctl00$CheckBoxCheckedTextBox" type="text" value="false" id="ctl00_CheckBoxCheckedTextBox" class="Invisible" /> <input name="ctl00$RefreshSeconds" type="text" value="1260000" id="ctl00_RefreshSeconds" class="Invisible" /> </form></body></html>
The button i need to click on has the name attribute value of
ctl00$PageAreaContentPlaceholder$ButtonNavigateToAccountingEnquiry is represented by the section of code below
<input type="submit" name="ctl00$PageAreaContentPlaceholder$ButtonNavigateToAccountingEnquiry" value="Accounting Enquiry" id="ctl00_PageAreaContentPlaceholder_ButtonNavigateToAccountingEnquiry" class="Buttons" style="font-weight:bold;height:25px;width:280px;" />
So far, i have tried the following but nothing happens. The page loads and the button remains unclicked.
FIRSTLY
Set htmlDoc = .document
Set htmlColl = htmlDoc.getElementsByTagName("input")
Do While htmlDoc.readyState <> "complete": DoEvents: Loop
For Each htmlInput In htmlColl
If Trim(htmlInput.getAttribute("class")) = "Buttons" and Trim(htmlInput.getAttribute("name")) = “ctl00$PageAreaContentPlaceholder$ButtonNavigateToAccountingEnquiry” Then
htmlInput.Click
Exit For
End If
Next htmlInput
SECONDLY
Set inp = IE.document.getElementsByTagName("input")
For Each itm In inp
If itm.Type = "submit" And itm.Value = " Accounting Enquiry " Then
itm.Select
itm.Click
End If
Next itm
Any suggestions would be greatley appreciated. I have noticed there is some Java code within the HTML source code but this means absolutely nothing to me.:doh:
I need to click a button on a website, below is the source code ( i have also attached this as a word document as it may be easier to see)
<head id="ctl00_Head1"><title> Enquiry Menu</title><link id="ctl00_StyleSheetLink" href="../StyleSheet/PdaStyleSheet.css" type="text/css" rel="stylesheet" /> <script language="javascript" src="../Script/Script.js"></script> <script language="javascript" src="../Script/SignaturePadScript.js"></script> <script language="javascript" src="Script/Script.js"></script> <script language="javascript" src="Script/SignaturePadScript.js"></script> <!-- need to put this reference in as it looks for scripts relative to the parent page, not the master page --> <!-- <script language="javascript" src="Script/Script.js"></script> <script language="javascript" src="Script/SignaturePadScript.js"></script> --> <script language="javascript"> var lastControl = null; /*function MasterPage_ShowErrorMessage(obj, errorHeading, errorText) { var popUpObject = document.getElementById("PopupDialogBox"); var imageObj = obj; if (imageObj != lastControl) { lastControl = imageObj; //get the position of the clicked object var coors = findPos(obj); //then add 15 px to each one so we don't cover up the exclamation mark coors[1] += 15; coors[0] += 15; popUpObject.style.top = coors[1] + 'px'; popUpObject.style.left = coors[0] + 'px'; popUpObject.style.width = 200; if (popUpObject.style.pixelLeft + popUpObject.style.pixelWidth > document.body.clientWidth) popUpObject.style.pixelLeft = event.clientX - 10 - popUpObject.style.pixelWidth; popUpObject.style.display = "block"; document.getElementById("PopupDialogBoxHeading").innerText = errorHeading; document.getElementById("PopupDialogBoxMessage").innerText = errorText; } else { lastControl = null; popUpObject.style.display = "none"; } event.cancelBubble = true; } //as the position in at which the object we're trying to render will be //relative to any parent it has with absolute positioning, we want to stop //adding to the co-ordinates at which to render the object as soon as we //hit a parent with an absolute position. function findPos(obj) { var curleft = curtop = 0; if (obj.offsetParent) { curleft = obj.offsetLeft; curtop = obj.offsetTop; while ((obj = obj.offsetParent) && (getElementStyle(obj, 'position', 'position') != 'absolute')) { curleft += obj.offsetLeft; curtop += obj.offsetTop; } } return [curleft,curtop]; }*/ //expects an element and the text representations of the style property //we care about (use both IE and CCS names so it will work if someone //uses a browser other than IE). function getElementStyle(elem, IEStyleProp, CSSStyleProp) { if (elem.currentStyle) { return elem.currentStyle[IEStyleProp]; } else if (window.getComputedStyle) { var compStyle = window.getComputedStyle(elem, ""); return compStyle.getPropertyValue(CSSStyleProp); } return ""; } function MasterPage_ShowErrorMessage(obj, errorHeading, errorText) { var popUpObject = document.getElementById("PopupDialogBox"); if (obj != lastControl) { lastControl = obj; popUpObject.style.left = event.clientX + 10; popUpObject.style.top = event.clientY + 10; popUpObject.style.width = 200; if (popUpObject.style.pixelLeft + popUpObject.style.pixelWidth > document.body.clientWidth) popUpObject.style.pixelLeft = event.clientX - 10 - popUpObject.style.pixelWidth; popUpObject.style.display = "block"; document.getElementById("PopupDialogBoxHeading").innerText = errorHeading; document.getElementById("PopupDialogBoxMessage").innerText = errorText; } else { lastControl = null; popUpObject.style.display = "none"; } event.cancelBubble = true; } function DropDownChange(selectedIndex) { document.getElementById("ctl00$DropDownListSelectedIndex").value = selectedIndex; //document.getElementById("ctl00$ctl19").disabled=true; } function TextBoxChange(value) { document.getElementById("ctl00$MessageDialogTextBoxText").value = value; } function CheckBoxChange(checked) { document.getElementById("ctl00$CheckBoxCheckedTextBox").value = checked; } </script></head><body scroll="no" onclick="CatchClick(window.event.srcElement); HidePopupIfVisible();" onload="getSignature('ctl00_PageAreaContentPlaceHolder_'); SetDefaultButton(); if (window.document.title!='Home'){SetFocus();}; AutoRefresh();" onresize="ResizeWindow(600, 800);" onkeydown="CatchKeyPress(window.event.keyCode, window.event.srcElement);"> <form name="aspnetForm" method="post" action="AccountingEnquiryMenu.aspx?RoleID=206" id="aspnetForm"><div><input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /><input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" /><input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTY0MzEyMDIwOA9kFgJmD2QWAgIDD2QWBAIBDxYCHglpbm5lcmh0bWwFIlBEJmFtcDtB IEFjY291bnRpbmcgLSBFbnF1aXJ5IE1lbnVkAgMPFgQeA3NyYwUVLi4vSW1hZ2UvbmJzbG9nbzM uZ2lmHgV0aXRsZQU+UHJvZHVjdGlvbiBFbnZpcm9ubWVudA0KQ1NQUFVJUzAyDQpCdWlsZDogNC 4wLjAuMCAoNC4wLjMzNjkuMSlkZEJJDGxYtPGALzuh0onm4Kxui0c4" /></div> <script type="text/javascript"> //<![CDATA[var theForm = document.forms['aspnetForm'];if (!theForm) { theForm = document.aspnetForm;}function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); }}//]]></script> <div> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWDALPj8D6CgKq7qvMCwLKuvL/DALwnLmMAwKwxYanBQLp6ubsBgKV7M2LCwLG1/yvDwKskqPbAQLC5OTqAwKgtMnpCwLStb6OCIGym7YlFfm4ZkOW4SRNSaIkPJcT" /></div> <div class="WrenMenuContainer"> <h1 id="ctl00_WrenMenuHeader">PD&A Accounting - Enquiry Menu</h1> <img src="../Image/nbslogo3.gif" id="ctl00_WrenMenuLogoImage" border="0" align="absMiddle" title="Production EnvironmentCSPPUIS02Build: 4.0.0.0 (4.0.3369.1)" /> <div> <ul id="ctl00_WrenMenuLinkButtonList"><li><a title="Exit the application" href="javascript:__doPostBack('ctl00$ctl01','')" style="display:inline-block;width:80px;margin-left:5px;">Exit</a></li></ul> <span id="ctl00_WrenMenuUserIdLabel"></span> </div> <div class="WrenMenuFadeStrip"></div> </div> <div class="UserMessageContainer"><span id="ctl00_MessageLabel"> </span></div> <!--<div style="padding:5px 10px 5px 10px; color:Firebrick; font-size:8pt;"><u>Summary</u> > <u>Accounting</u> > <u>Search</u> > <b>Rule Detail</b></div>--> <div style="text-align:center;"> <h3>Accounting Enquiry Main Menu</h3> <input type="submit" name="ctl00$PageAreaContentPlaceholder$ButtonNavigateToPaymentEnquiry" value="Payment Enquiry" id="ctl00_PageAreaContentPlaceholder_ButtonNavigateToPaymentEnquiry" class="Buttons" style="font-weight:bold;height:25px;width:280px;" /> <br /><br /> <input type="submit" name="ctl00$PageAreaContentPlaceholder$ButtonNavigateToExtractEnquiry" value="Extract Enquiry" id="ctl00_PageAreaContentPlaceholder_ButtonNavigateToExtractEnquiry" class="Buttons" style="font-weight:bold;height:25px;width:280px;" /> <br /><br /> <input type="submit" name="ctl00$PageAreaContentPlaceholder$ButtonNavigateToTransitEnquiry" value="Trial Balance" id="ctl00_PageAreaContentPlaceholder_ButtonNavigateToTransitEnquiry" class="Buttons" style="font-weight:bold;height:25px;width:280px;" /> <br /><br /> <input type="submit" name="ctl00$PageAreaContentPlaceholder$ButtonNavigateToSummaryEnquiry" value="Summary Enquiry" id="ctl00_PageAreaContentPlaceholder_ButtonNavigateToSummaryEnquiry" class="Buttons" style="font-weight:bold;height:25px;width:280px;" /> <br /><br /> <input type="submit" name="ctl00$PageAreaContentPlaceholder$ButtonNavigateToAccountingEnquiry" value="Accounting Enquiry" id="ctl00_PageAreaContentPlaceholder_ButtonNavigateToAccountingEnquiry" class="Buttons" style="font-weight:bold;height:25px;width:280px;" /> <br /><br /> <input type="submit" name="ctl00$PageAreaContentPlaceholder$ButtonNavigateToRuleEnquiry" value="Rule Enquiry" id="ctl00_PageAreaContentPlaceholder_ButtonNavigateToRuleEnquiry" class="Buttons" style="font-weight:bold;height:25px;width:280px;" /> <br /><br /> </div> <div id="ctl00_ButtonContainer" class="ButtonContainer"></div> <div id="PopupDialogBox" class="PopupDialogBox"> <h1 id="PopupDialogBoxHeading">Message Heading</h1> <div id="PopupDialogBoxMessage">Message text of some sort.... dah dah dahhhh...</div> </div> <input name="ctl00$DropDownListSelectedIndex" type="text" value="0" id="ctl00_DropDownListSelectedIndex" class="Invisible" /> <input name="ctl00$MessageDialogTextBoxText" type="text" id="ctl00_MessageDialogTextBoxText" class="Invisible" /> <input name="ctl00$CheckBoxCheckedTextBox" type="text" value="false" id="ctl00_CheckBoxCheckedTextBox" class="Invisible" /> <input name="ctl00$RefreshSeconds" type="text" value="1260000" id="ctl00_RefreshSeconds" class="Invisible" /> </form></body></html>
The button i need to click on has the name attribute value of
ctl00$PageAreaContentPlaceholder$ButtonNavigateToAccountingEnquiry is represented by the section of code below
<input type="submit" name="ctl00$PageAreaContentPlaceholder$ButtonNavigateToAccountingEnquiry" value="Accounting Enquiry" id="ctl00_PageAreaContentPlaceholder_ButtonNavigateToAccountingEnquiry" class="Buttons" style="font-weight:bold;height:25px;width:280px;" />
So far, i have tried the following but nothing happens. The page loads and the button remains unclicked.
FIRSTLY
Set htmlDoc = .document
Set htmlColl = htmlDoc.getElementsByTagName("input")
Do While htmlDoc.readyState <> "complete": DoEvents: Loop
For Each htmlInput In htmlColl
If Trim(htmlInput.getAttribute("class")) = "Buttons" and Trim(htmlInput.getAttribute("name")) = “ctl00$PageAreaContentPlaceholder$ButtonNavigateToAccountingEnquiry” Then
htmlInput.Click
Exit For
End If
Next htmlInput
SECONDLY
Set inp = IE.document.getElementsByTagName("input")
For Each itm In inp
If itm.Type = "submit" And itm.Value = " Accounting Enquiry " Then
itm.Select
itm.Click
End If
Next itm
Any suggestions would be greatley appreciated. I have noticed there is some Java code within the HTML source code but this means absolutely nothing to me.:doh: