我无法使用IE.document.getElementbyID
将文本加载到IE中的搜索框中。我包含了目前使用的代码。我相信我在这里遗漏了一些东西。这是我在这里包含的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
答案 0 :(得分:1)
您尝试捕获的对象没有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")
,例如这样的事情(未经测试):
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