运行时错误“424”:对象所需的IE.Document.GetElementById文本框内iframe
我有问题在IE中使用IE.document.getElementbyID
加载文本到search框我包括我使用的代码到目前为止。 我相信我在这里错过了一些东西。 这是我在这里包括的iframe代码的更新
<iframe tabindex="-1" id="WorkdayApp" src="javascript:""" style="left: -1000px; top: -1000px; width: 0px; height: 0px; border-top-color: currentColor; border-right-color: currentColor; border-bottom-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; position: absolute;"> <input class="gwt-TextBox GPNS02MDDGJ" aria-label="Expanded, multiSelectPrompt, 0 items selected, Use up and down arrows to select. or Type in a search" type="text" placeholder="search" data-automation-id="searchBox"/>
“
Sub workdayrep() '******************************* Dim iframe As Object Dim textbox As Object '******************************* Dim IE As InternetExplorer Set IE = New InternetExplorer Set iframe = IE.document.getElementById("WorkdayApp") Set textbox = iframe.contentWindow.document.getElementById("searchBox") IE.Visible = True IE.navigate "https://wd.workday.com/142.htmld" Application.StatusBar = "Page Loading" 'Do While IE.Busy ' Application.Wait DateAdd("s", 1, Now) ' Loop Application.Wait Now + TimeValue("00:00:10") textbox.Value = "TEST" ' Application.StatusBar = "Check" End Sub
你试图捕捉的对象没有ID
属性,它有一个"data-automation-id"
属性。
<input class="gwt-TextBox GPNS02MDDGJ" aria-label="Expanded, multiSelectPrompt, 0 items selected, Use up and down arrows to select. or Type in a search" type="text" placeholder="search" data-automation-id="searchBox"/>
因此, getElementByID
将总是返回Nothing
(除非有一些具有该ID的其他元素,在这种情况下显然不存在!)。 你需要一个暴力循环getElementsByClassName("gwt-TextBox GPNS02MDDGJ")
,例如像这样( 未经testing ):
Dim itm For each itm in iFrame.contentWindow.document.getElementsByClassName("gwt-TextBox GPNS02MDDGJ") If itm.getAttribute("data-automation-id", 2) = "searchBox" Then itm.setAttribte("data-automation-id", "test") Exit For End If Next