Sneerz Posted June 16, 2015 Share Posted June 16, 2015 (edited) 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 NextThank you. Edited June 17, 2015 by Sneerz Link to comment Share on other sites More sharing options...
Exit Posted June 16, 2015 Share Posted June 16, 2015 Cannot find an error. All working perfect.Here a screenshot. App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Sneerz Posted June 16, 2015 Author Share Posted June 16, 2015 (edited) 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 June 16, 2015 by Sneerz Link to comment Share on other sites More sharing options...
Exit Posted June 16, 2015 Share Posted June 16, 2015 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) Sneerz 1 App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Sneerz Posted June 17, 2015 Author Share Posted June 17, 2015 Thank you so much, I don't know how I missed @extended, it was right on the page description of _IETagNameGetColelction! This works perfectly. Link to comment Share on other sites More sharing options...
Exit Posted June 17, 2015 Share Posted June 17, 2015 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' App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now