
I was looking for the element, "CompExports", in Google Chrome. The HTML from Dev Tools is below. (Dev Tools are available by pressing F12 in Chrome, or right-clicking the relevant element on the webpage and left-clicking "Inspect" on the pop-up menu.)
Code: Select all
<td role="gridcell" style="" aria-describedby="clientList_ClientName">CompExports</td>
Code: Select all
ChromeFindElements>SID,xpath,//td[@role='gridcell'],elements
Code: Select all
ChromeFindElements>SID,xpath,//td[@aria-describedby='clientList_ClientName'],elements
…and to make sure that each frame switch was successful (res=0).
…but the macro always ended with "elements_count=0".
So much frustration--but I pressed on. I scoured the page source code. I desperately searched the pane source code for any mention of frames, “src=” or other clues for the whereabouts of this elusive element. For the entire weekend, I sifted through hundreds of frames and even searched hundreds of frames within those frames!
No elements found.

I was totally ready to pay someone to help me find this annoying, aggravating needle in a haystack.
Finally, after more than 48 painful, progress-free hours…a breakthrough.
Glancing at my second monitor, my eyes just happened to land on an “<iframe>” tag in the Dev Tools code. Curious, I looked for a “src=” and found a partial URL. A new hope!
I tried the line
Code: Select all
ChromeFindElements>SID,xpath,//iframe[@src='/MS/Search/Export.cvs'],elements
I loaded the parameters into my custom SRT to search 200 frames for this iframe tag with src='/MS/Search/Export.cvs'. Match found in frame 6.
“Baby steps,” I thought to myself.
After some trial and error, I had:
Code: Select all
GoSub>SwitchFrames,5,ER5
ChromeFindElements>SID,xpath,//iframe[@src='/MS/Search/Export.cvs'],elements
ChromeSwitchFrame>SID,element,elements_1,res
If>res<>0
Mdl>Error switching to Export.cvs frame. res=%res%%CRLF%The macro will almost certainly fail. Click OK to continue.
**BREAKPOINT**
EndIf
Code: Select all
ChromeFindElements>SID,xpath,//td[@aria-describedby='clientList_ClientName'],elements
Custom SRT to search all the frames…. Match found in frame 0!
OMG! I knew I was so close! I had spent dozens of hours hunting this burdensome pest--and now it was within my grasp! I was overwhelmed with relief, excitement, hope and many feelings all at once! I literally ran into the other room to share the news with my gf.
I added a few more lines of code.
Code: Select all
GoSub>SwitchFrames,0,ER6
DelArray>elements
ChromeFindElements>SID,xpath,//td[@aria-describedby='clientList_ClientName'],elements
I added the last bit of code to parse the various elements and find the one I wanted.
Code: Select all
//Click the one that's named "CompExports." Examine all found elements and get their names.
Let>k=0
Repeat>k
//Increment the counter.
Add>k,1
ChromeGetElementData>SID,elements_%k%,attribute/innerHTML,res
If>res=CompExports
//This element is the one the macro should click.
ChromeElementAction>SID,elements_%k%,click
Goto>ClickNextOrMapping
EndIf
Until>k,elements_count
1) Learn that in this unique case, searching the page and pane source code wasn’t advantageous.
2) Search the code in Dev Tools for <iframe> tags.
3) Search all the webpage’s frames for the <iframe> in question.
4) Switch to that frame containing the pertinent <iframe>.
5) Search all the webpage’s frames for the desired element.
6) Switch to the relevant frame with that element.
7) Search for that specific element.
8. Parse the elements found for the one I wanted.
I was so happy to have conquered this large obstacle that had stood in my way for days! While I realize that for many, it was but a tiny puddle, for me it was a very perplexing puzzle that really challenged my critical thinking, creativity and commitment. I took some small pride knowing that this element was buried pretty deep compared to any other I’d chased, and writing the custom SRTs (see below) helped find the element more easily.
TL;DR
When searching for elements in Chrome (and possibly Edge), looking at the page or pane source code (Ctrl + U) may not yield any clues. It may be best to Inspect the element in question (twice), click the code in the Dev Tools and use Ctrl + F to find “<iframe” or similar--probably the instance immediately preceding the element you want. Then use ChromeFindElements and XPath to find that pane, ChromeSwitchFrame to switch to it and then search for your element. Example here.