Question

In VBA, Is it possible to have a GetElementBySrc command?

My macro is entering data into a webpage textbox and clicking search.

I have a Do function that loops until Internet Explorer is in ready state but Internet Explorer hits a ready state before the search is complete/result page loads.

There's an image "processing.gif" that appears on the search page while waiting for the results to show. I'm thinking I might have more luck if I can write an "If...Then" command that will wait until the image is no longer on the search page.

The tag I'm trying to find will say

<img alt="search" src"images/processing.gif" />

ADDITIONAL THOUGHT

I was thinking about something like this.

Do
  If IE.Document.GetElementsByTagName("img").Attributes("src").Value = "images/processing.gif" Is Nothing Then
      Exit Do
  Else
      DoEvents
  End If
Loop
Was it helpful?

Solution

Here's what I've used in similar circumstances...

Do Until InStr(1, ie.Document.body.innerhtml, "images/processing.gif", vbTextCompare) = 0
  DoEvents
Loop

OTHER TIPS

You can grab the img elements and just loop through till you get the innertext as well

dim imgElm

for each imgElm in ie.Document.getElementsByTagName("img")
    if imgElm.innertext = "images/processing.gif" then
    'do something
    exit for
    end if
next
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top