Sign in to follow this  
Followers 0
Sanchezu

how to get a IE tag value by class name ?

13 posts in this topic

#1 ·  Posted (edited)

Hi.

I'm new to autoit, but I have some scripting experience.

I'm trying to get the value of a DIV tag from a html page. This DIV tag has no "id" or "name" attributes so I can't use _IEGetObjByName or _IEGetObjById.

My only option is to search the DIV tag by "class" attribute....

If anyone can help me with this, thanks in advance.

Edited by Sanchezu

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This is the code I'm using:

#include <IE.au3>
$oIE = _IECreate ("http://www.test.com", 0, 0, 1, 0)

$tags = $oIE.document.GetElementsByTagName("div")
For $tag in $tags
    $class_value = $tag.GetAttribute("class")
    If $class_value = "levelBar" Then
        MsgBox(0, "Level: ", "Level found :)")
    EndIf
Next

_IEQuit ($oIE)

I get no msg box, so I'm wondering why it cannot find the div tag with class attribute ="levelBar"

Edited by Sanchezu
1 person likes this

Share this post


Link to post
Share on other sites

IE has problems with that func. use className instead:

$class_value = $tag.className


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

that worked :P

thanks a lot

Share this post


Link to post
Share on other sites

You can retrieve the Tagname by _IETagNameGetCollection, look it up in the help


0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Share this post


Link to post
Share on other sites

I used the same code and my problem is that I can put any value in the if $class_value = "any value" then msgbox and it will launch the msgbox... Can somebody explain that to me please?

Share this post


Link to post
Share on other sites

Use

If String($class_value) = "levelBar" Then

If there is no Classname, 0 is returned. This forces a numeric comparison instead of the string one you want... it converts your string to 0 and 0 = 0.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Thank you (:

Is there anyway to click on a button when I get his class? I've just tried with _IEAction but it doesn't works... But I'm not sure this is possible

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Assuming you want to click the DIV you were searching for above (though most buttons are <inputs>)

#include <IE.au3>
$oIE = _IECreate ("http://www.test.com", 0, 0, 1, 0)
 
$oCorrectObj = ""

$tags = $oIE.document.GetElementsByTagName("div")
For $tag in $tags
$class_value = $tag.GetAttribute("class")
If string($class_value) = "levelBar" Then
    $oCorrectObj = $tag

MsgBox(0, "Level: ", "Level found :)")
    ExitLoop

EndIf
Next
 
If IsObj ( $oCorrectObj ) Then
 
_IEAction ($oCorrectObj, "click")


EndIF


_IEQuit ($oIE)

edit: just realized this is a super old post, but the same structure can be used for whatever your element is

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Yep that's what I've tried but it didn't work :/

Share this post


Link to post
Share on other sites

bling8d ... what web page are you attempting to interact with. I can take a look at it and see how to help you?


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

It's a very well known website and I guess nobody here will answer me If I'd give it x)

Share this post


Link to post
Share on other sites

_IENavigate($object, 'javascript:document.querySelector(".classname").href')

easiest method is by far the above. my one lline example simply evals javascript to select the class then returns the href. i know this posst is old but i figured someone might bee interested to know this can be done in one line

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  
Followers 0