Jump to content

Recommended Posts

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
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
Posted

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

Posted

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

0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

  • 3 years later...
Posted

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?

Posted

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

Posted

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

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.
Posted

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

  • 4 years later...
Posted

_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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...