1

I am trying to access an element of a popup window, which seems to be embedded in an iframe. Below is the html I am dealing with. The line I am interested in below is ...OK.../a> . I have left some html out as it is rather large and I did not think it would be helpful. If needed I can post. I have tried many combinations to access this but so far nothing gets that OK button. Below is my best guess code that does not work.

$ie.Document.getElementsByTagName("A") | Where {$_.getAttributeNode 
('class').Value -eq 'btn btn3d PopupBtn'} 

<html>
<head>...</head>
  <body>
    <iframe id="12345"src="https://example.com/html/messagepopup.html"  
     frameborder="0" style="width:100%; height: 154px;">
     <!-- COMMENT HERE about the software
     -->
     <html>
     <head>
     <link href="https://example.com/path/to/custompage.css"rel=stylesheet">
     </link>
     </head>
     <body class="popupmsg" onload="onload()">
     <div class="PopupMsgFooter" id="PopupMsgFooter">
     <a class="btn bnt3d PopupBtn" href="#" arid="2"arwindowid="0">OK</a>
     </body>
     </html>
     </iframe>   
 </body>
</html> 

2 Answers 2

1

Here is the final answer. Very close to the below but my final answer is convoluted. I had two iframes in this HTML DOC and for some reason searching by src would not return the correct result. Instead I had to eliminate the other. Weird but works. Second line is a hodge podge of stuff. I googled and found that trying contentwindow may work. After a number of iterations, I came up with the below line. Instead of contentdocument, I had to use contentwindow. (Anyone know why??) I also needed to change the where clause, due to there being two buttons under the same classname. The unique value for me here was the arid. Once I got a reference to the correct object it was easy to see the needed changes. Serious KUDOS to wOxxOm for this.....

$iframe =  $ie.Document.getElementsByTagName('iframe') 
    | Where { $_.id -notcontains 'pinghtml' }

$ok = $iframe.contentwindow.document.body.getElementsByTagName('a') 
    | Where {$_.getAttributeNode('arid').Value -eq '2'}

$ok.click()
Sign up to request clarification or add additional context in comments.

Comments

0

The button is inside an iframe, and an iframe has its own separate DOM.

  1. Find the iframe element
  2. Find the button inside the iframe's contentDocument

$iframe = $ie.Document.getElementsByTagName('iframe') | 
    Where { $_.src -contains '/messagepopup.html' }
$ok = $iframe.contentDocument.getElementsByTagName('a') |
    Where { $_.className -eq 'btn bnt3d PopupBtn' }

2 Comments

Thanks much. This is good info, but did not work for me. Oddly the first line $iframe is empty. I can get the iframe element using the ID though, as a temporary solution as that will change. When I have the $iframe object, the second line gives a null valued expression error. contentdocument is the issue I think. Using "document" returns nothing.
Finally! Thanks to w0xx0m getting me on the right track. Would not have been possible without the above answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.