Get ID for button in iframe and click it via VBA

I am trying to programmatically click a button of a popup iframe. Here is the code for the iframe:
<iframe width="100%" id="iMaintenancePopup" src="../oa/Common/maintenancePopup.aspx" frameborder="0" scrolling="no" style="height: 723px;"></iframe>

Open in new window

Here is the screenshot for the popup iframe:OfficeAllyPopup.pngHow do I get the ID for the button that states: "I acknowledge this message" and how do I click it using VBA?
LVL 39
thenelsonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MacroShadowCommented:
Firstly, right-click on the button and select "Inspect Element" (the exact term may be different depending on the browser you're using).
Next, find the button id.
Finally, use some code like this:
Public Sub EE_Demo()

    Dim objIE As Object
    Dim objElement As Object

    ' Create InternetExplorer Object
    Set objIE = CreateObject("InternetExplorer.Application")

    ' Make sure the Internet Explorer window is visible
    objIE.Visible = True
    
    ' Navigate to your URL
    objIE.Navigate "your link"

    ' Wait while IE loading...
    Do While objIE.Busy
        Application.Wait DateAdd("s", 3, Now)
    Loop

    ' Get the button
    Set objElement = objIE.document.getElementsById("buttonid")
    
    ' Click the button
    objElement.Click

    ' Clean up
    Set objIE = Nothing
    Set objElement = Nothing

End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
thenelsonAuthor Commented:
In IE, I right-clicked on the button and selected "Inspect Element" but the button did not display in the DOM Explorer (or any of the other tabs).
MacroShadowCommented:
Try in Chrome or Firefox.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

thenelsonAuthor Commented:
Ok, so I found that the button ID is "btnAcknowledge".

But
    IE.document.getElementsById("buttonid").click
does not work, The automation does not see the button because it is in an iframe.
    ie.document.frames["iMaintenancePopup"].document.body.getElementById("btnAcknowledge").click
also does not work.

I am looking for the correct syntax for referencing the button in an iframe.
thenelsonAuthor Commented:
Or some other way to close the popup iframe if it pops up.
thenelsonAuthor Commented:
I found the correct code to click the button:
IE.Document.getElementById("iMaintenancePopup").contentDocument.getElementById("btnAcknowledge").Click
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.