使用VBA访问iframe中的元素

使用VBA访问iframe中的元素,vba,powerpoint,Vba,Powerpoint,我正在尝试访问iframe的元素,它位于使用Wix Site Builder、使用PowerPoint VBA制作的网页上 我尝试了在谷歌和其他网页上找到的所有东西,但我想不出来。最常见的错误是当我尝试使用contentDocument时出现的“自动错误”和当我尝试使用contentWindow时出现的“访问被拒绝” Dim objIE As InternetExplorer Set objIE = New InternetExplorer objIE.Visible = True objIE.

我正在尝试访问iframe的元素,它位于使用Wix Site Builder、使用PowerPoint VBA制作的网页上

我尝试了在谷歌和其他网页上找到的所有东西,但我想不出来。最常见的错误是当我尝试使用
contentDocument
时出现的“自动错误”和当我尝试使用
contentWindow
时出现的“访问被拒绝”

Dim objIE As InternetExplorer
Set objIE = New InternetExplorer
objIE.Visible = True
objIE.navigate "https://pptgamespt.wixsite.com/mppp/tests2"
Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop
Pausecode (2)
objIE.document.getElementsByTagName("iframe")(0).contentDocument.getElementById("input").Value = "some value"
Dim objIE作为InternetExplorer
Set objIE=新的InternetExplorer
objIE.Visible=True
objIE.navigate“https://pptgamespt.wixsite.com/mppp/tests2"
Do While objIE.Busy=True或objIE.readyState 4:DoEvents:Loop
Pausecode(2)
objIE.document.getElementsByTagName(“iframe”)(0.contentDocument.getElementById(“输入”).Value=“一些值”

我正在尝试更改id为“input”的输入值,它位于iframe内部,没有类或id。上面的代码是我最后尝试的抛出错误“Automation error”的代码。

我认为IE会遇到同源策略问题。您可以获取iframe的src并导航到该问题

Option Explicit
Public Sub SendInfo()
    Dim ie As New InternetExplorer

    With ie
        .Visible = True
        .Navigate2 "https://pptgamespt.wixsite.com/mppp/tests2"

        While .Busy Or .readyState < 4: DoEvents: Wend

        .Navigate2 ie.document.querySelector("iframe").src

        While .Busy Or .readyState < 4: DoEvents: Wend

        .document.querySelector("#input").Value = "Bob"
        .document.querySelector("#send").Click

        While .Busy Or .readyState < 4: DoEvents: Wend
        Stop
        .Quit
    End With
End Sub

问题是,我需要的网页和iframe在同一时间。他们将“一起工作”。这是怎么回事?我想从Wix数据库发送和获取信息,为此我将在网站上放置一个代码,将文本发送到输入中。在此之前,我想确保我可以更改输入的值,因为它对Wix输入元素不起作用,所以我决定使用htmliframe。我希望我说得很清楚。有没有一种方法可以尝试复制你想要的步骤和我可以测试的预期结果?目前,我已经回答了前面提到的问题,值得澄清这一额外步骤。
Option Explicit
Public Sub EnterInfo()
    Dim d As WebDriver
    Set d = New ChromeDriver
    Const URL = "https://pptgamespt.wixsite.com/mppp/tests2"

    With d
        .Start "Chrome"
        .get URL
        .SwitchToFrame .FindElementByCss("iframe")
        Do
        Loop While .FindElementsByCss("#input").Count = 0
        .FindElementByCss("#input").SendKeys "tada"
        Stop
        .Quit
    End With
End Sub