0

I am having trouble loading text into a search box in IE using IE.document.getElementbyID I am including the code I am using so far. I am sure I am missing something here. This is an update of the iframe code I am including here

<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
Alfredo A.
  • 3
  • 3
  • 8
  • 1
    while I can't test it, I still suggest you use `While IE.Busy Or IE.ReadyState <> 4: DoEvents: Wend` instead of `Application.Wait`... also, are you sure `IE.document.getElementById("searchBox")` returns just one object? just stop your code before your `getElementById` via `stop` or a breakpoint and put in your "watches" directly `IE.document.getElementById("searchBox")` and then check what it does return... I simply do not think that you can access it directly via `.Value` – Dirk Reichel Jul 05 '16 at 17:54
  • I just looked at the code of the site I am trying to input the text is it loooks like it is inside an iframe – Alfredo A. Jul 05 '16 at 18:02
  • Sometimes IE automation in VBA can be a little strange. You can try defining your search value as a string `Dim SV as String` `SV = "TEST"` then referring to this directly `IE.document.getElementById("searchBox").Value = SV` give that a try, I had to do a lot of this in my recent web scraping project. – Glitch_Doctor Jul 05 '16 at 18:39
  • Also `Dim IE as Object` not `Variant` – Glitch_Doctor Jul 05 '16 at 18:43
  • 1
    `IE.document.getElementById("searchBox").Value = "TEST"` raises an error because some part of that namespace isn't (yet) an object. Most likely case is that `getElementById` returns a `Nothing`, which raises the 424 when attempting to assign to `Nothing.Value`... You need to wait for the page to finish loading using the method @DirkReichel mentions in comment, above. – David Zemens Jul 05 '16 at 18:58
  • 1
    @DavidZemens As it looks to me, The error is not due to the "not waiting enough time". While `Application.Wait` isn't the smart way, it still should work... From the beginning it looked much more like he simply isn't able to catch the right object. That said: this question isn't a dublicate to my eyes. – Dirk Reichel Jul 05 '16 at 19:14
  • Re-opened esp. in light of additional information! – David Zemens Jul 05 '16 at 19:16

1 Answers1

1

The object you're trying to catch doesn't have an ID attribute, it has a "data-automation-id" attribute.

<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"/>

As such, getElementByID will always return Nothing (unless there is some other element with that ID, which there obviously is not in this case!). You'll need a brute force loop over getElementsByClassName("gwt-TextBox GPNS02MDDGJ"), e.g. something like this (untested):

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
David Zemens
  • 53,033
  • 11
  • 81
  • 130
  • Yep I tried using the ElementsByClassName however this would only return with a Run-time error 438 "Object doesn't support this property or method". – Alfredo A. Jul 05 '16 at 20:27
  • See [this](http://stackoverflow.com/questions/7410949/javascript-document-getelementsbyclassname-compatibility-with-ie) possible workaround for older versions of IE which don't support that method. – David Zemens Jul 05 '16 at 20:31
  • See also [this similar answer](http://stackoverflow.com/questions/23476502/getelementsbyclassname-open-ie-vs-msxml2-methods) (of mine) which may be easier to implement. – David Zemens Jul 05 '16 at 20:34