2

I am trying to automate access to a web page with VBA. I am in thru the login screen, but I am not able to click one of the elements to get to the search screen. Normally this isn't too hard, but it seems like this element is in an iframe? I'm not sure if that is why I can't see it. I've tried to loop all the A tags and get nop returns. I've tried to use query selector to reach it which i was shown in the past and worked. Both to no avail. I've tried 4 different ways to grab a tag with the idea of doing a ForEach loop after & matching some attribute & clicking:

    Set HTMLAs = HTMLDoc.getElementsByTagName("a")
    Set HTMLAs = HTMLDoc.getElementsByTagName("tr")
    Set HTMLAs = HTMLDoc.getElementsByTagName("td")
    Set HTMLAs = HTMLDoc.getElementsByTagName("div")

And i've tried:

HTMLDoc.querySelector("a[title='Policy']").Click
'HTMLDoc.querySelector("a[href='/PolicySearch/policySearch_v30.cfm?module=policy&actionType=lookup']").Click    'no
'HTMLDoc.querySelector("a[href='/PolicySearch/policySearch_v30.cfm?module=policy&actionType=lookup']").Click    'no
'HTMLDoc.querySelector("A[href='/PolicySearch/policySearch_v30.cfm?module=policy&actionType=lookup']").Click    'NO
'HTMLDoc.querySelector("A[title='Policy']").Click                                                                   'no

and none of those grab the element.

This is the html of the element i want to click:

<A title=Policy style="FONT-SIZE: 8pt; FONT-FAMILY: arial" 
href="/PolicySearch/policySearch_v30.cfm? 
module=policy&amp;actionType=lookup" target=main nowrap>&nbsp; Lookup Policy 
&nbsp;</A>

and this is the top of the frame when i first get on the page i want:

<FRAMESET id=defaultFrame frameSpacing=0 border=0 frameBorder=no 
rows=70,21,*,21,1><FRAME noResize src="/systemInfo/ScriptX/titleBar.cfm" 
frameBorder=0 name=titleBar scrolling=no application="yes"><FRAME noResize 
src="/producerTOC.cfm" frameBorder=0 name=producerTOC scrolling=no 
application="yes"><FRAMESET id=BottomRow cols=1,*><FRAME noResize 
src="toc.cfm" frameBorder=0 name=toc marginWidth=0 scrolling=no 
application="yes"><FRAME noResize src="main.cfm" frameBorder=0 name=main 
application="yes"></FRAMESET><FRAME noResize 
src="/systemInfo/ScriptX/footerFrame.cfm" frameBorder=0 name=footerFrame 
scrolling=no application="yes"><FRAME noResize src="" frameBorder=0 
name=utilityFrame scrolling=no application="yes"><NOFRAMES></NOFRAMES> 

But from here i'm not sure how to proceed. Any advice or direction much appreciated.

Screenshot of html from the iframe down to Lookup Policy. ScreenShot

Search form after clicking "Lookup Policy"

<FORM id=SearchForm onsubmit="return _CF_checkSearchForm(this)" method=get 
name=SearchForm action=/PolicySearch/policyAdvLookup_v30.cfm 
target=searchResultFrame><TABLE class=TableSelection>
<TBODY>
<TR>
<TD class=HeaderCell>Policy Search</TD></TR>
<TR>
<TD class=SelectionCell>
<TABLE class=NoBorder>
<TBODY>
<TR>
<TD class=Right style="WIDTH: 2%" noWrap>&nbsp;</TD>
<TD class="Right Bold" style="WIDTH: 20%" noWrap>Search Criteria</TD>
<TD noWrap><A onclick="ToggleMode();return false;" id=ToggleModeLink        
class=FloatR href="">- Advanced Search -</A> <INPUT onfocus=this.select(); 
id=searchField class=upperCase size=30 name=searchField class="upperCase" 
jQuery112406813183503798275="4"><BUTTON id=SearchButton style="WIDTH: 130px" 
type=submit name=SearchButton>Search</BUTTON></TD></TR>
<TR>
<TD id=SearchLabel class="Right Bold" colSpan=2 noWrap>Search By</TD>
<TD noWrap><INPUT onclick=LoadParam(1); id=searchOption title="Policy # / 
Name" class=Blend CHECKED type=radio value=name name=searchOption>Policy # / 
Name &nbsp; <INPUT onclick=LoadParam(2); id=searchOption title="Insured 
Address" class=Blend type=radio value=address name=searchOption>Insured 
Address &nbsp; <INPUT onclick=LoadParam(3); id=searchOption title="Dwelling 
Location" class=Blend type=radio value=location name=searchOption>Dwelling 
Address &nbsp; 
<DIV id=LineSearchOptions><SPAN id=LineSearchOptions_1 
name="LineSearchOptions_1"><INPUT onclick=LoadParam(6,true); id=searchOption 
title="Driver Name / Lic Num" class=Blend type=radio value=name 
name=searchOption>Driver Name / Lic Num &nbsp; <INPUT 
onclick=LoadParam(6,false); id=searchOption title="Vehicle VIN" class=Blend 
type=radio value=VIN name=searchOption>Vehicle VIN &nbsp; </SPAN></DIV></TD> 
</TR>
<TR id=PolicyTypeRow name="PolicyTypeRow">
<TD class="Right Bold" colSpan=2 noWrap>Policy Type</TD>
<TD noWrap><SELECT onchange=ShowLineOptions(this.value); id=policyType 
name=policyType> <OPTION selected value=0>All Policy Types</OPTION> <OPTION 
value=4>Homeowner Policies</OPTION> <OPTION value=3>Dwelling Fire 
Policies</OPTION> <OPTION value=1>Personal Auto Policies</OPTION></SELECT> 
</TD></TR>
<TR id=SearchCriteriaDisplay name="SearchCriteriaDisplay">
<TD class=Right noWrap><A onclick="ClearParam(1);return false;" id=aClear 
href="" name=aClear>[ X ]</A></TD>
<TD id=strSearchParamLbl class="Right Bold" noWrap 
name="strSearchParamLbl">Policy # / Name</TD>
<TD noWrap><SPAN id=strSearchParamDisplay name="strSearchParamDisplay"> 
</SPAN><INPUT id=strSearchParam type=hidden name=strSearchParam></TD></TR>
<TR id=SearchCriteriaDisplay name="SearchCriteriaDisplay">
<TD class=Right noWrap><A onclick="ClearParam(2);return false;" id=aClear 
href="" name=aClear>[ X ]</A></TD>
<TD id=strSearchParamLbl class="Right Bold" noWrap 
name="strSearchParamLbl">Insured Address</TD>
<TD noWrap><SPAN id=strSearchParamDisplay name="strSearchParamDisplay"> 
</SPAN><INPUT id=strSearchParam type=hidden name=strSearchParam></TD></TR>
<TR id=SearchCriteriaDisplay name="SearchCriteriaDisplay">
<TD class=Right noWrap><A onclick="ClearParam(3);return false;" id=aClear 
href="" name=aClear>[ X ]</A></TD>
<TD id=strSearchParamLbl class="Right Bold" noWrap 
name="strSearchParamLbl">Dwelling Location</TD>
<TD noWrap><SPAN id=strSearchParamDisplay name="strSearchParamDisplay"> 
</SPAN><INPUT id=strSearchParam type=hidden name=strSearchParam></TD></TR>
 <TR id=SearchCriteriaDisplay name="SearchCriteriaDisplay">
 <TD class=Right noWrap><A onclick="ClearParam(4);return false;" id=aClear 
 href="" name=aClear>[ X ]</A></TD>
 <TD id=strSearchParamLbl class="Right Bold" noWrap 
 name="strSearchParamLbl">Phone&nbsp;</TD>
<TD noWrap><SPAN id=strSearchParamDisplay name="strSearchParamDisplay"> 
</SPAN><INPUT id=strSearchParam type=hidden name=strSearchParam></TD></TR>
 <TR id=TimeframeRow name="TimeframeRow">
 <TD class="Right Bold" colSpan=2 noWrap>Recent Policies Only</TD>
<TD noWrap><INPUT id=historyTimeFrame CHECKED type=checkbox value=1200 
 name=historyTimeFrame> Exclude policies that expired prior to December 
 1918</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><INPUT 
 id=strSearchNameNum type=hidden name=strSearchNameNum> <INPUT 
 id=strSearchAddress type=hidden name=strSearchAddress> <INPUT 
 id=strSearchLocation type=hidden name=strSearchLocation> <INPUT 
 id=strSearchPhone type=hidden name=strSearchPhone> <INPUT 
 id=strSearchEmail type=hidden name=strSearchEmail> <INPUT id=strSearchLine 
 type=hidden name=strSearchLine> <INPUT id=strSearchLineType type=hidden 
 name=strSearchLineType> <INPUT id=displayType type=hidden value=0 
 name=displayType> <INPUT type=hidden value=0 name=isQuoteSearch> <INPUT 
 type=hidden value=policy name=module> <INPUT type=hidden value=lookup 
 name=actionType> </FORM>

When i Click on the webpage that holds the few search/navigate options:

<FRAMESET id=defaultFrame frameSpacing=0 border=0 frameBorder=no 
rows=70,21,*,21,1><FRAME noResize src="/systemInfo/ScriptX/titleBar.cfm" 
frameBorder=0 name=titleBar scrolling=no application="yes"><FRAME noResize 
src="/producerTOC.cfm" frameBorder=0 name=producerTOC scrolling=no 
application="yes"><FRAMESET id=BottomRow cols=1,*><FRAME noResize 
src="toc.cfm" frameBorder=0 name=toc marginWidth=0 scrolling=no 
application="yes"><FRAME noResize src="main.cfm" frameBorder=0 name=main 
application="yes"></FRAMESET><FRAME noResize 
src="/systemInfo/ScriptX/footerFrame.cfm" frameBorder=0 name=footerFrame 
scrolling=no application="yes"><FRAME noResize src="" frameBorder=0 
name=utilityFrame scrolling=no application="yes"><NOFRAMES></NOFRAMES> 
</FRAMESET>

Table:

<TABLE id=MainTabText style="BORDER-TOP: 0px; HEIGHT: 19px; BORDER-RIGHT: 
0px; WIDTH: 100%; BORDER-BOTTOM: 0px; LEFT: 0px; MARGIN: 0px; BORDER-LEFT: 
0px; TOP: 0px" cellSpacing=0 cellPadding=0 name="MainTabText"><TBODY>
<TR style="FONT-WEIGHT: bold">
<TD style="FONT-SIZE: 8pt; BORDER-TOP: 0px; FONT-FAMILY: arial; BORDER- 
RIGHT: 0px; WIDTH: 1%; VERTICAL-ALIGN: middle; BORDER-BOTTOM: 0px; COLOR: 
black; PADDING-BOTTOM: 0px; TEXT-ALIGN: left; PADDING-TOP: 0px; PADDING- 
LEFT: 10px; BORDER-LEFT: 0px; LINE-HEIGHT: 8pt; PADDING-RIGHT: 0px" noWrap>| 
<A title=Policy style="FONT-SIZE: 8pt; FONT-FAMILY: arial" 
href="/PolicySearch/policySearch_v30.cfm? 
module=policy&amp;actionType=lookup" target=main nowrap>&nbsp; Lookup Policy 
&nbsp;</A> |<A title=Reports style="FONT-SIZE: 8pt; FONT-FAMILY: arial" 
href="/Reports/reports.cfm" target=main nowrap>&nbsp; Reports &nbsp;</A> |<A 
title=Agencies style="FONT-SIZE: 8pt; FONT-FAMILY: arial" 
href="ProducerInfo/producerInfoLayout.cfm?producerID=10003" target=main 
nowrap>&nbsp; Agency Info &nbsp;</A> |<A title="Upload Documents" 
style="FONT-SIZE: 8pt; FONT-FAMILY: arial" 
href="/PolicySearch/policySearch_v30.cfm? 
module=Upload&amp;actionType=lookup" target=main nowrap>&nbsp; Upload 
Documents &nbsp;</A> |<A title="Batch Viewer" style="FONT-SIZE: 8pt; FONT- 
FAMILY: arial" href="/batch/batchViewer/batchViewerlayout.cfm" target=main 
nowrap>&nbsp; Batch Viewer &nbsp;</A> |</TD>
<TD style="FONT-SIZE: 8pt; BORDER-TOP: 0px; FONT-FAMILY: arial; BORDER- 
RIGHT: 0px; WIDTH: 99%; VERTICAL-ALIGN: middle; BORDER-BOTTOM: 0px; COLOR: 
black; PADDING-BOTTOM: 0px; TEXT-ALIGN: right; PADDING-TOP: 0px; PADDING- 
LEFT: 0px; BORDER-LEFT: 0px; LINE-HEIGHT: 8pt; PADDING-RIGHT: 10px" 
noWrap>&nbsp;| <A style="FONT-SIZE: 8pt; FONT-FAMILY: arial" 
href="/main.cfm" target=main nowrap>&nbsp; Home &nbsp;</A> | <A 
onclick="LogoutCheck();blur();return false;" style="FONT-SIZE: 8pt; FONT- 
FAMILY: arial" href="" nowrap>&nbsp; Logout &nbsp;</A> |</TD></TR></TBODY> 

QHarr
  • 83,427
  • 12
  • 54
  • 101
Jim Carney
  • 87
  • 2
  • 10

1 Answers1

1

The selector is correct

a[title=Policy]

If there is a frame/iframe use on of its properties to then access its contentDocument. E.g. if there is an id for the frame

ie.document.getElementById(frameid").contentDocument.querySelector("a[title=Policy]").click
QHarr
  • 83,427
  • 12
  • 54
  • 101
  • I apologies, I pasted in the wrong html as the Lookup Policy html. I've fixed my original post. HI'm going to link a screen shot of the rest of the html now in my original post. I cant seem to copy it all. – Jim Carney Dec 17 '18 at 21:47
  • you can copy the entire by right clicking the html tag and select copy element. You would then need to post link via https://pastebin.com/ – QHarr Dec 17 '18 at 21:53
  • Quick update: So I tried it with IE.Document.querySelector("a[title='Policy']").Click and I get an error, 438 - object doesn't support this property, so perhaps It's finding the object but it's not clickable. – Jim Carney Dec 17 '18 at 21:54
  • That is interesting. It's an a tag so should be clickable. Can you not add another .navigate2 "baseURL/PolicySearch/policySearch_v30.cfm" where base url is the protocol (http/s) + domain (abc.com) part of the original url? – QHarr Dec 17 '18 at 21:59
  • Ok I copied the element with styles & pasted it on the website. https://pastebin.com/rBtSDRRg is the link it gave me. Not sure how else to get it over here. – Jim Carney Dec 17 '18 at 22:02
  • So I thought so too & tried: IE.Navigate "https://fednat.live.ptsapp.com/default/PolicySearch/policySearch_v30.cfm?module=policy&actionType=lookup" putting the beginning of the webpage together with the href but i get an error, 404 i think. When you click the link manually in the webpage though the URL never changes, but the display does – Jim Carney Dec 17 '18 at 22:05
  • So when we manually click "Lookup Policy" it changes the middle of the screen but not the URL. This form comes on screen. I'm adding it to the bottom of my post now. – Jim Carney Dec 17 '18 at 22:20
  • Cool. I will have a look. – QHarr Dec 17 '18 at 22:41
  • There is no frame/iframe in that html – QHarr Dec 17 '18 at 22:44
  • Quick question is Navigate2 different from Navigate in IE? – Jim Carney Dec 17 '18 at 22:47
  • Is the method which is now supposed to be used. https://stackoverflow.com/questions/4538097/ie-com-object-difference-between-methode-navigate-and-navigate2 – QHarr Dec 17 '18 at 22:50
  • I added the FrameSet in the post when i click on the webpage in that area. There is also a table when i click there. The table does contain the Policy Lookup href – Jim Carney Dec 17 '18 at 23:50
  • So I'm not sure I'm reading it right, but it looks to me my target is in a table(last set of HTML in my original post), in a cell within a row, but that cell seems to contain several Href items. There seem to be at least two cells in the row, 1 row. I'm guessing that's why I cant "click" or reference the link? – Jim Carney Dec 18 '18 at 02:09
  • One additional comment. I did find "top.main.document.getElementsByTagName("IFRAME")" this in the webpage. I've never seen top.main.document as a path before & so I dont know if i need to refer to items the same way. I've tried but no success so far. – Jim Carney Dec 18 '18 at 20:37
  • Is your element within an iframe? – QHarr Dec 18 '18 at 20:38
  • its hard for me to tell, but i think its within a frame in a table within that frame. i did new pastebin https://pastebin.com/wzFBD5qB the top line #1, i had to paste seperatly from 2-235, but in the browser line 1 is in the chain 2 is indented off of that. I keep trying to reference objects i see on the page visuaslly, but the only thing i can grab is Set HTMLButton = HTMLDoc.getElementById("defaultFrame") – Jim Carney Dec 18 '18 at 21:13
  • I just saw your edit on the post, with "ie.document.getElementById(frameid").contentDocument.querySelector("a[title=Policy]").click" I'll run it tomorrow & let you know! Thank you. – Jim Carney Dec 18 '18 at 22:26
  • No worries. Speak later. – QHarr Dec 18 '18 at 22:26
  • I'm still stuck. There is no Id on the Frame. there is one on the frame set, but not the frame, but it has a name. this works Set HTMLFrame = HTMLDoc.getElementsByName("producerTOC")(0) & if i debug print the tag i get "Frame". This does not work: IE.Document.getElementsByName("producerTOC")(0).contentDocument.querySelector("a[title=Policy]").Click though. – Jim Carney Dec 19 '18 at 19:05
  • Gives error 438. But i got it to work another way. Set HTMLFrameDoc = HTMLDoc.getElementsByName("producerTOC")(0) to set another document reference. Then Set Links = HTMLFrameDoc.Links & loop thru the links. I matched the getAttribute("href") in the loop & then click on the match. That works but i thought on my initial Set line i would have needed Set HTMLFrameDoc = HTMLDoc.getElementsByName("producerTOC")(0).contentDocument, but no. that doesnt work. So problem solved, but I'm confused to why. Interesting. – Jim Carney Dec 19 '18 at 20:04
  • If you can match the href in a loop then you can remove the loop. – QHarr Dec 19 '18 at 20:06
  • You should then have been able to do HTMLDoc.getElementsByName("producerTOC")(0) .querySelector("a[title=Policy]").click if you say you don't need contentDocument though I am surprised at that. – QHarr Dec 19 '18 at 20:12
  • I tried too after i got the Link.click to work. HTMLDoc.getElementsByName("producerTOC")(0).querySelector("a[title=Policy]").Click 'no 438. I'm surprised too because it would seem ok. I tied with IE.Document too. Next week i'm going to play with it a bit because my test code gets sloppier as I try to solve problems thru the website. Once i have all the names working I build out a clean job & make sure it pauses where it needs to. Thank you for the help though or I would not have gotten this. – Jim Carney Dec 19 '18 at 20:24
  • Pleasure. Keep it up. – QHarr Dec 19 '18 at 20:26