Jump to content
Sign in to follow this  
Sneerz

[solved] Checking website for a particular tag and continuing if visible

Recommended Posts

Sneerz

I am working with the Autoit internet explorer interface and I am having a problem with the _IETagNameGetCollection method. I am trying to get a particular attribute from the "a" tag and then if it is found, to continue running the script. If the attribute is not found inside one of these tags (which would result from the website changing or the element being removed), then the script would be stopped. I used a method to count up the number of total elements of the webpage and if it gets to the end of the webpage, then the script stops if the element isn't found. This is a problem because the number of elements has to be hardcoded and if the webpage adds more of these tags to it, the script will be broken. The question I have is there a way to dynamically get the number of tags found using _IETagNameGetCollection? I tried to print out the value after collecting tags, but it returns nothing, which makes me believe that it just returns an object to be interfaced with, and not a visible number. 

Here is my code. 

#include <IE.au3>
#include <MsgBoxConstants.au3>
#include <Date.au3>

$oIE1 = _IECreate("http://sneerz.com")
$hwnd1 = _IEPropertyGet($oIE1, "hwnd")
Sleep(3000)

Local $oLinks = _IETagNameGetCollection($oIE1, "a")
    For $oLink In $oLinks
        $class_value = $oLink.GetAttribute("class")
        If string($class_value) = " active" Then
            MsgBox(0, "", "Found element: " & $oLink.innerText)
        EndIf
Next

Thank you.

Edited by Sneerz

Share this post


Link to post
Share on other sites
Sneerz

Yes it finds it perfectly, but how would I modify my script to make it so that if the element is not found, the script ends? Or how would I get the number of tags found from _IETagNameGetCollection?

Edit: For example this code doesn't work properly because this loops through every single "a" tag. What I need to do is find out how many "a" tags there are then to search for that many tags, and then if it has searched all of them and hasn't found " active", the script ends. If it does find it, then the script continues until it can no longer find it.

#include <IE.au3>
#include <MsgBoxConstants.au3>
#include <Date.au3>

$oIE1 = _IECreate("http://sneerz.com")
$hwnd1 = _IEPropertyGet($oIE1, "hwnd")
Sleep(3000)

Local $oLinks = _IETagNameGetCollection($oIE1, "a")
    For $oLink In $oLinks
        $class_value = $oLink.GetAttribute("class")
        If string($class_value) = " active" Then
            MsgBox(0, "", "Found element: " & $oLink.innerText)
        Else
Exit
EndIf

Next
Edited by Sneerz

Share this post


Link to post
Share on other sites
Exit

Just use @Extended after  _IETagNameGetCollection()

#include <IE.au3>
#include <MsgBoxConstants.au3>
#include <Date.au3>
$oIE1 = _IECreate("http://sneerz.com")
$hwnd1 = _IEPropertyGet($oIE1, "hwnd")
$oLinks = _IETagNameGetCollection($oIE1, "a")
$tags = @extended

MsgBox(262144, Default, $tags & " A-Tags found", 0)
For $oLink In $oLinks

    $class_value = $oLink.GetAttribute("class")
    If String($class_value) = " active" Then

        MsgBox(0, "", "Found element: " & $oLink.innerText)
    EndIf

Next
MsgBox(64 + 262144, Default, "Exit", 0)

 

  • Like 1

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites
Sneerz

Thank you so much, I don't know how I missed @extended, it was right on the page description of _IETagNameGetColelction! This works perfectly. 

Share this post


Link to post
Share on other sites
Exit

Glad that I could help. :)

Don't forget to mark the tread as solved. Prepend title with [solved]. And perhaps give my solution a 'like this' :)


My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

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
Sign in to follow this  

×