Jump to content

[SOLVED] Parse elements of a webpage NOT created by _IECreate


 Share

Recommended Posts

Hello,

Let's take a simple example to illustrate my case.

I open a webpage with the command _IECreate and I parse all its elements :

#include <IE.au3>

$oIE = _IECreate("http://www.york.ac.uk/teaching/cws/wws/webpage1.html")

$oElements = _IETagNameAllGetCollection($oIE)
For $oElement In $oElements
    ConsoleWrite("Tagname: " & $oElement.tagname & @CRLF & "Id: " & $oElement.id & @CRLF & "InnerText: " & $oElement.innerText & @CRLF & "--------------------------------" & @CRLF)
Next

Now let's imagine I simulate a click with MouseClick to the link "lesson two" at the bottom of this webpage. A new webpage will open :

http://www.york.ac.uk/teaching/cws/wws/webpage2.html

I'd like to get the elements (tagname, id, innertext) of this new webpage, just like I got them for the first webpage. But for this, I presume I would have to get a new $oIE2 Object variable of an InternetExplorer.Application, in order to be able to use the _IETagNameAllGetCollection once again.

How am I supposed to do this ?

Thank you !

 

Edited by Faalamva
Link to comment
Share on other sites

Thank you, I managed to create a working example with your hint.

Here it is below :

#include <IE.au3>

$oIE = _IECreate("http://www.york.ac.uk/teaching/cws/wws/webpage1.html")
WinSetState("", "", @SW_MAXIMIZE)

$oElements = _IETagNameAllGetCollection($oIE)
For $oElement In $oElements
    If $oElement.innerText = "EXERCISE" Then
        $oIE.document.parentwindow.scroll(0, 500)
        MsgBox(0, "", "WebPage elements have been parsed. Let's move the mouse to EXERCISE for example.")
        MouseMove($oElement.getBoundingClientRect().left + $oIE.document.parentwindow.screenleft, $oElement.getBoundingClientRect().top + $oIE.document.parentwindow.screentop)
    EndIf
Next

MsgBox(0, "", "Now let's simulate a click to the ""lesson two"" link at the bottom of the page.")
_IELinkClickByText($oIE, "lesson two")

MsgBox(0, "", "Now let's try to locate FONT ATTRIBUTES in the new webpage.")

; Stupid WinGetTitle adds " - Internet Explorer" after the real window title, so we have to remove it otherwise the attachment won't work
;MsgBox(0, "", WinGetTitle("[ACTIVE]"))
$oIE2 = _IEAttach(StringReplace(WinGetTitle("[ACTIVE]"), " - Internet Explorer", ""))

$oElements2 = _IETagNameAllGetCollection($oIE2)
For $oElement2 In $oElements2
    ;ConsoleWrite("Tagname: " & $oElement2.tagname & @CRLF & "innerText: " & $oElement2.innerText)
    If $oElement2.innerText = " FONT ATTRIBUTES" And $oElement2.tagName = "FONT" Then
        MsgBox(0, "", "New WebPage elements have been parsed. Let's move the mouse to FONT ATTRIBUTES for example.");
        MouseMove($oElement2.getBoundingClientRect().left + $oIE2.document.parentwindow.screenleft, $oElement2.getBoundingClientRect().top + $oIE2.document.parentwindow.screentop)
    EndIf
Next

Do you know if there's a simpler way to attach the new webpage (for example, by using its URL) ?

I would be very interested in using the new URL instead of the webpage title.

Edited by Faalamva
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...