Jump to content
Alan_Hsu

Automating Internet Explorer problem

Recommended Posts

Alan_Hsu

Hello, I am new to autoit. I was experimenting with automating COM objects like internet explorer but I had a problem with finding elements on a website.

I learned from youtube tutorials that you can find an element by using $var = .document.getElementsByTagName("text element here") but the text that I wanted to find appeared under multiple lines, like this:

<p id="line1" class>
    <span class="oung">TEXT HERE</span>
</p>
<p id="line2" class>
    <span class="oung">TEXT HERE</span>
</p>
<p id="line3" class>
    <span class="oung">TEXT HERE</span>
</p>

The text in every one of them is the same, the only thing that's different is the line1 and line2. How would I find the TEXT HERE from line1 without the program finding the other ones?

Share this post


Link to post
Share on other sites
SmOke_N

Look at the _IECreate() / _IEAttach() / _IEGetObjByID / _IEGetObjBy...etc functions.

Your example would look something like this pseudo code:

#include <IE.au3>

Global $goIE = _IECreate("some website url here")
If Not IsObj($goIE) Then
    MsgBox(16, "Error 1", "Not an object")
    Exit
EndIf

Global $goLine1 = _IEGetObjById($goIE, "line1")
If Not IsObj($goLine1) Then
    MsgBox(16, "Error 2", "Not an object")
    Exit
EndIf

; get the value of the text
MsgBox(64, "Value", _IEPropertyGet($goLine1, "outertext"))

 


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Alan_Hsu

Thank you! I've been stuck on this for hours. I have another question, since the text in the html changes sometimes, is it possible to wait until something happens, and then get the value of the text? I'd like to wait until a line appears:

<span id="textIcon" class="red" style="opacity: 1;"></span>

before getting the value of the text, and while it isn't there yet, the program will sleep. Is this possible?

Share this post


Link to post
Share on other sites
SmOke_N

Well, your question is open ended.  Yes it's possible.

Maybe something like:

Global $goIE = _IECreate etc...
Global $goObj
Do
    Sleep(100)
    $goObj = _IEGetObjByID($goIE, "textIcon")
Until IsObj($goObj)
... rest of code

So just a word to the wise, do your homework, read the help file, try some code, post what doesn't work.  I'm not a fan of doing the work myself ;)


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Alan_Hsu

Ok thanks, I will make sure to read the help file!

Share this post


Link to post
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

×