title: Clicking on an HTML element with QuerySelector thru VBA
body: <p>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 &amp; matching some attribute &amp; clicking:</p>
  
  <pre><code>    Set HTMLAs = HTMLDoc.getElementsByTagName("a")
      Set HTMLAs = HTMLDoc.getElementsByTagName("tr")
      Set HTMLAs = HTMLDoc.getElementsByTagName("td")
      Set HTMLAs = HTMLDoc.getElementsByTagName("div")
  </code></pre>
  
  <p>And i've tried:</p>
  
  <pre><code>HTMLDoc.querySelector("a[title='Policy']").Click
  'HTMLDoc.querySelector("a[href='/PolicySearch/policySearch_v30.cfm?module=policy&amp;actionType=lookup']").Click    'no
  'HTMLDoc.querySelector("a[href='/PolicySearch/policySearch_v30.cfm?module=policy&amp;amp;actionType=lookup']").Click    'no
  'HTMLDoc.querySelector("A[href='/PolicySearch/policySearch_v30.cfm?module=policy&amp;amp;actionType=lookup']").Click    'NO
  'HTMLDoc.querySelector("A[title='Policy']").Click                                                                   'no
  </code></pre>
  
  <p>and none of those grab the element.</p>
  
  <p>This is the html of the element i want to click:</p>
  
  <pre><code>&lt;A title=Policy style="FONT-SIZE: 8pt; FONT-FAMILY: arial" 
  href="/PolicySearch/policySearch_v30.cfm? 
  module=policy&amp;amp;actionType=lookup" target=main nowrap&gt;&amp;nbsp; Lookup Policy 
  &amp;nbsp;&lt;/A&gt;
  </code></pre>
  
  <p>and this is the top of the frame when i first get on the page i want:</p>
  
  <pre><code>&lt;FRAMESET id=defaultFrame frameSpacing=0 border=0 frameBorder=no 
  rows=70,21,*,21,1&gt;&lt;FRAME noResize src="/systemInfo/ScriptX/titleBar.cfm" 
  frameBorder=0 name=titleBar scrolling=no application="yes"&gt;&lt;FRAME noResize 
  src="/producerTOC.cfm" frameBorder=0 name=producerTOC scrolling=no 
  application="yes"&gt;&lt;FRAMESET id=BottomRow cols=1,*&gt;&lt;FRAME noResize 
  src="toc.cfm" frameBorder=0 name=toc marginWidth=0 scrolling=no 
  application="yes"&gt;&lt;FRAME noResize src="main.cfm" frameBorder=0 name=main 
  application="yes"&gt;&lt;/FRAMESET&gt;&lt;FRAME noResize 
  src="/systemInfo/ScriptX/footerFrame.cfm" frameBorder=0 name=footerFrame 
  scrolling=no application="yes"&gt;&lt;FRAME noResize src="" frameBorder=0 
  name=utilityFrame scrolling=no application="yes"&gt;&lt;NOFRAMES&gt;&lt;/NOFRAMES&gt; 
  </code></pre>
  
  <p></p>
  
  <p>But from here i'm not sure how to proceed. Any advice or direction much appreciated.</p>
  
  <p>Screenshot of html from the iframe down to Lookup Policy.
  <a href="https://i.stack.imgur.com/7rmdw.png" rel="nofollow noreferrer">ScreenShot</a></p>
  
  <p>Search form after clicking "Lookup Policy"</p>
  
  <pre><code>&lt;FORM id=SearchForm onsubmit="return _CF_checkSearchForm(this)" method=get 
  name=SearchForm action=/PolicySearch/policyAdvLookup_v30.cfm 
  target=searchResultFrame&gt;&lt;TABLE class=TableSelection&gt;
  &lt;TBODY&gt;
  &lt;TR&gt;
  &lt;TD class=HeaderCell&gt;Policy Search&lt;/TD&gt;&lt;/TR&gt;
  &lt;TR&gt;
  &lt;TD class=SelectionCell&gt;
  &lt;TABLE class=NoBorder&gt;
  &lt;TBODY&gt;
  &lt;TR&gt;
  &lt;TD class=Right style="WIDTH: 2%" noWrap&gt;&amp;nbsp;&lt;/TD&gt;
  &lt;TD class="Right Bold" style="WIDTH: 20%" noWrap&gt;Search Criteria&lt;/TD&gt;
  &lt;TD noWrap&gt;&lt;A onclick="ToggleMode();return false;" id=ToggleModeLink        
  class=FloatR href=""&gt;- Advanced Search -&lt;/A&gt; &lt;INPUT onfocus=this.select(); 
  id=searchField class=upperCase size=30 name=searchField class="upperCase" 
  jQuery112406813183503798275="4"&gt;&lt;BUTTON id=SearchButton style="WIDTH: 130px" 
  type=submit name=SearchButton&gt;Search&lt;/BUTTON&gt;&lt;/TD&gt;&lt;/TR&gt;
  &lt;TR&gt;
  &lt;TD id=SearchLabel class="Right Bold" colSpan=2 noWrap&gt;Search By&lt;/TD&gt;
  &lt;TD noWrap&gt;&lt;INPUT onclick=LoadParam(1); id=searchOption title="Policy # / 
  Name" class=Blend CHECKED type=radio value=name name=searchOption&gt;Policy # / 
  Name &amp;nbsp; &lt;INPUT onclick=LoadParam(2); id=searchOption title="Insured 
  Address" class=Blend type=radio value=address name=searchOption&gt;Insured 
  Address &amp;nbsp; &lt;INPUT onclick=LoadParam(3); id=searchOption title="Dwelling 
  Location" class=Blend type=radio value=location name=searchOption&gt;Dwelling 
  Address &amp;nbsp; 
  &lt;DIV id=LineSearchOptions&gt;&lt;SPAN id=LineSearchOptions_1 
  name="LineSearchOptions_1"&gt;&lt;INPUT onclick=LoadParam(6,true); id=searchOption 
  title="Driver Name / Lic Num" class=Blend type=radio value=name 
  name=searchOption&gt;Driver Name / Lic Num &amp;nbsp; &lt;INPUT 
  onclick=LoadParam(6,false); id=searchOption title="Vehicle VIN" class=Blend 
  type=radio value=VIN name=searchOption&gt;Vehicle VIN &amp;nbsp; &lt;/SPAN&gt;&lt;/DIV&gt;&lt;/TD&gt; 
  &lt;/TR&gt;
  &lt;TR id=PolicyTypeRow name="PolicyTypeRow"&gt;
  &lt;TD class="Right Bold" colSpan=2 noWrap&gt;Policy Type&lt;/TD&gt;
  &lt;TD noWrap&gt;&lt;SELECT onchange=ShowLineOptions(this.value); id=policyType 
  name=policyType&gt; &lt;OPTION selected value=0&gt;All Policy Types&lt;/OPTION&gt; &lt;OPTION 
  value=4&gt;Homeowner Policies&lt;/OPTION&gt; &lt;OPTION value=3&gt;Dwelling Fire 
  Policies&lt;/OPTION&gt; &lt;OPTION value=1&gt;Personal Auto Policies&lt;/OPTION&gt;&lt;/SELECT&gt; 
  &lt;/TD&gt;&lt;/TR&gt;
  &lt;TR id=SearchCriteriaDisplay name="SearchCriteriaDisplay"&gt;
  &lt;TD class=Right noWrap&gt;&lt;A onclick="ClearParam(1);return false;" id=aClear 
  href="" name=aClear&gt;[ X ]&lt;/A&gt;&lt;/TD&gt;
  &lt;TD id=strSearchParamLbl class="Right Bold" noWrap 
  name="strSearchParamLbl"&gt;Policy # / Name&lt;/TD&gt;
  &lt;TD noWrap&gt;&lt;SPAN id=strSearchParamDisplay name="strSearchParamDisplay"&gt; 
  &lt;/SPAN&gt;&lt;INPUT id=strSearchParam type=hidden name=strSearchParam&gt;&lt;/TD&gt;&lt;/TR&gt;
  &lt;TR id=SearchCriteriaDisplay name="SearchCriteriaDisplay"&gt;
  &lt;TD class=Right noWrap&gt;&lt;A onclick="ClearParam(2);return false;" id=aClear 
  href="" name=aClear&gt;[ X ]&lt;/A&gt;&lt;/TD&gt;
  &lt;TD id=strSearchParamLbl class="Right Bold" noWrap 
  name="strSearchParamLbl"&gt;Insured Address&lt;/TD&gt;
  &lt;TD noWrap&gt;&lt;SPAN id=strSearchParamDisplay name="strSearchParamDisplay"&gt; 
  &lt;/SPAN&gt;&lt;INPUT id=strSearchParam type=hidden name=strSearchParam&gt;&lt;/TD&gt;&lt;/TR&gt;
  &lt;TR id=SearchCriteriaDisplay name="SearchCriteriaDisplay"&gt;
  &lt;TD class=Right noWrap&gt;&lt;A onclick="ClearParam(3);return false;" id=aClear 
  href="" name=aClear&gt;[ X ]&lt;/A&gt;&lt;/TD&gt;
  &lt;TD id=strSearchParamLbl class="Right Bold" noWrap 
  name="strSearchParamLbl"&gt;Dwelling Location&lt;/TD&gt;
  &lt;TD noWrap&gt;&lt;SPAN id=strSearchParamDisplay name="strSearchParamDisplay"&gt; 
  &lt;/SPAN&gt;&lt;INPUT id=strSearchParam type=hidden name=strSearchParam&gt;&lt;/TD&gt;&lt;/TR&gt;
   &lt;TR id=SearchCriteriaDisplay name="SearchCriteriaDisplay"&gt;
   &lt;TD class=Right noWrap&gt;&lt;A onclick="ClearParam(4);return false;" id=aClear 
   href="" name=aClear&gt;[ X ]&lt;/A&gt;&lt;/TD&gt;
   &lt;TD id=strSearchParamLbl class="Right Bold" noWrap 
   name="strSearchParamLbl"&gt;Phone&amp;nbsp;&lt;/TD&gt;
  &lt;TD noWrap&gt;&lt;SPAN id=strSearchParamDisplay name="strSearchParamDisplay"&gt; 
  &lt;/SPAN&gt;&lt;INPUT id=strSearchParam type=hidden name=strSearchParam&gt;&lt;/TD&gt;&lt;/TR&gt;
   &lt;TR id=TimeframeRow name="TimeframeRow"&gt;
   &lt;TD class="Right Bold" colSpan=2 noWrap&gt;Recent Policies Only&lt;/TD&gt;
  &lt;TD noWrap&gt;&lt;INPUT id=historyTimeFrame CHECKED type=checkbox value=1200 
   name=historyTimeFrame&gt; Exclude policies that expired prior to December 
   1918&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;INPUT 
   id=strSearchNameNum type=hidden name=strSearchNameNum&gt; &lt;INPUT 
   id=strSearchAddress type=hidden name=strSearchAddress&gt; &lt;INPUT 
   id=strSearchLocation type=hidden name=strSearchLocation&gt; &lt;INPUT 
   id=strSearchPhone type=hidden name=strSearchPhone&gt; &lt;INPUT 
   id=strSearchEmail type=hidden name=strSearchEmail&gt; &lt;INPUT id=strSearchLine 
   type=hidden name=strSearchLine&gt; &lt;INPUT id=strSearchLineType type=hidden 
   name=strSearchLineType&gt; &lt;INPUT id=displayType type=hidden value=0 
   name=displayType&gt; &lt;INPUT type=hidden value=0 name=isQuoteSearch&gt; &lt;INPUT 
   type=hidden value=policy name=module&gt; &lt;INPUT type=hidden value=lookup 
   name=actionType&gt; &lt;/FORM&gt;
  </code></pre>
  
  <p>When i Click on the webpage that holds the few search/navigate options:</p>
  
  <pre><code>&lt;FRAMESET id=defaultFrame frameSpacing=0 border=0 frameBorder=no 
  rows=70,21,*,21,1&gt;&lt;FRAME noResize src="/systemInfo/ScriptX/titleBar.cfm" 
  frameBorder=0 name=titleBar scrolling=no application="yes"&gt;&lt;FRAME noResize 
  src="/producerTOC.cfm" frameBorder=0 name=producerTOC scrolling=no 
  application="yes"&gt;&lt;FRAMESET id=BottomRow cols=1,*&gt;&lt;FRAME noResize 
  src="toc.cfm" frameBorder=0 name=toc marginWidth=0 scrolling=no 
  application="yes"&gt;&lt;FRAME noResize src="main.cfm" frameBorder=0 name=main 
  application="yes"&gt;&lt;/FRAMESET&gt;&lt;FRAME noResize 
  src="/systemInfo/ScriptX/footerFrame.cfm" frameBorder=0 name=footerFrame 
  scrolling=no application="yes"&gt;&lt;FRAME noResize src="" frameBorder=0 
  name=utilityFrame scrolling=no application="yes"&gt;&lt;NOFRAMES&gt;&lt;/NOFRAMES&gt; 
  &lt;/FRAMESET&gt;
  </code></pre>
  
  <p>Table:</p>
  
  <pre><code>&lt;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"&gt;&lt;TBODY&gt;
  &lt;TR style="FONT-WEIGHT: bold"&gt;
  &lt;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&gt;| 
  &lt;A title=Policy style="FONT-SIZE: 8pt; FONT-FAMILY: arial" 
  href="/PolicySearch/policySearch_v30.cfm? 
  module=policy&amp;amp;actionType=lookup" target=main nowrap&gt;&amp;nbsp; Lookup Policy 
  &amp;nbsp;&lt;/A&gt; |&lt;A title=Reports style="FONT-SIZE: 8pt; FONT-FAMILY: arial" 
  href="/Reports/reports.cfm" target=main nowrap&gt;&amp;nbsp; Reports &amp;nbsp;&lt;/A&gt; |&lt;A 
  title=Agencies style="FONT-SIZE: 8pt; FONT-FAMILY: arial" 
  href="ProducerInfo/producerInfoLayout.cfm?producerID=10003" target=main 
  nowrap&gt;&amp;nbsp; Agency Info &amp;nbsp;&lt;/A&gt; |&lt;A title="Upload Documents" 
  style="FONT-SIZE: 8pt; FONT-FAMILY: arial" 
  href="/PolicySearch/policySearch_v30.cfm? 
  module=Upload&amp;amp;actionType=lookup" target=main nowrap&gt;&amp;nbsp; Upload 
  Documents &amp;nbsp;&lt;/A&gt; |&lt;A title="Batch Viewer" style="FONT-SIZE: 8pt; FONT- 
  FAMILY: arial" href="/batch/batchViewer/batchViewerlayout.cfm" target=main 
  nowrap&gt;&amp;nbsp; Batch Viewer &amp;nbsp;&lt;/A&gt; |&lt;/TD&gt;
  &lt;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&gt;&amp;nbsp;| &lt;A style="FONT-SIZE: 8pt; FONT-FAMILY: arial" 
  href="/main.cfm" target=main nowrap&gt;&amp;nbsp; Home &amp;nbsp;&lt;/A&gt; | &lt;A 
  onclick="LogoutCheck();blur();return false;" style="FONT-SIZE: 8pt; FONT- 
  FAMILY: arial" href="" nowrap&gt;&amp;nbsp; Logout &amp;nbsp;&lt;/A&gt; |&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt; 
  </code></pre>
  
  <p></p>