1

Here is the part of the HTML document that I'm trying to scrape from:

<div id="abc" class="outer">   
    ::before
    <div class="inner"></div>
    ::after
</div>

I tried to get the innerHTML of this snippet using

Set Elements = Document.getElementsByClassName("outer")
MsgBox Elements(0).innerHTML

The only thing that pops up in the message box is (without quotes):

"<div class="inner"></div>"

innerHTML seems to ignore the ::before and ::after CSS pseudo-elements. Is there any way to grab these or determine if they are even there?

The reason I'm asking is that when the application I'm trying to automate is in a loading state, the ::before and ::after elements are there. Once it is out of a loading state, these elements disappear.

Thank you

5
  • i do not think it is possible with inline styles. Commented Jun 14, 2017 at 15:46
  • related: What do ::before and ::after mean? Commented Jun 14, 2017 at 15:51
  • If you get the HTML in a text response instead of xmldom you could string manipulate to extract everything after 'class="outer">' and before '' I had to make a string manipulating function at work to handle poorly written HTML code that won't load in to an xmldom object and it works great for even large html files. Commented Jun 14, 2017 at 17:05
  • @jamheadart Do you have the string manipulating function on hand? Commented Jun 14, 2017 at 17:16
  • @jamheadart I ended up finding a solution (see my answer). Thank you for your suggestion. Commented Jun 14, 2017 at 19:28

1 Answer 1

1

I figured it out. I ended up using a different method than trying to find ::before and ::after.

Notes: I observed how the HTML document changed as the search went on and noticed that the parent of the HTML snippet I included above changed when the application entered or exited a loading state.

<div id="snippetParent" class="overlay" style="width: 100%; height: 100%; top: 0px; left: 0px; position: absolute; display: block;">

    <div id="abc" class="outer">
        <div class="inner"></div>
    </div>

</div>

The "Style" attribute's "display" property changed to "display: block" while loading, and changed to "display: none" when it was not loading.

There was also a popup that appeared if the application was taking too long to load (popup ID is "popup" for the purpose of this question). This popup makes the style mentioned above go from block to none. I had to include in the while loop below a condition for when the popup appears.

The "good" boolean is false until any indicators of loading disappear. Then it becomes true and consequently exits the while loop.

Here is my code:

Do While good = False
    For Each tx In Split(Document.getElementById("snippetParent").Style.cssText, "; ")
        If tx = "display: block" Then
            good = False
            UpdateBrowser BB:=Browser, waitSeconds:="02"
        ElseIf tx = "display: none" Then
            txtDocument = ""
            On Error Resume Next
            txtDocument = Document.getElementById("popup").innerHTML

            If txtDocument = "<b>Retrieving Data...</b>" Then
                Beep
                UpdateBrowser BB:=Browser, waitSeconds:="02"
            Else
                good = True
            End If
        Else
            'Not display
        End If
    Next tx
Loop
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.