Sanchezu Posted March 14, 2009 Share Posted March 14, 2009 (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 March 14, 2009 by Sanchezu Link to comment Share on other sites More sharing options...
Sanchezu Posted March 14, 2009 Author Share Posted March 14, 2009 (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 March 14, 2009 by Sanchezu realtebo 1 Link to comment Share on other sites More sharing options...
ProgAndy Posted March 14, 2009 Share Posted March 14, 2009 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 Link to comment Share on other sites More sharing options...
Sanchezu Posted March 14, 2009 Author Share Posted March 14, 2009 that worked thanks a lot Link to comment Share on other sites More sharing options...
TerarinK Posted March 14, 2009 Share Posted March 14, 2009 You can retrieve the Tagname by _IETagNameGetCollection, look it up in the help 0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E Link to comment Share on other sites More sharing options...
bling8d Posted August 22, 2012 Share Posted August 22, 2012 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? Link to comment Share on other sites More sharing options...
DaleHohm Posted August 22, 2012 Share Posted August 22, 2012 UseIf String($class_value) = "levelBar" ThenIf 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 Link to comment Share on other sites More sharing options...
bling8d Posted August 22, 2012 Share Posted August 22, 2012 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 Link to comment Share on other sites More sharing options...
jdelaney Posted August 22, 2012 Share Posted August 22, 2012 (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 August 22, 2012 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. Link to comment Share on other sites More sharing options...
bling8d Posted August 22, 2012 Share Posted August 22, 2012 Yep that's what I've tried but it didn't work :/ Link to comment Share on other sites More sharing options...
Blue_Drache Posted August 23, 2012 Share Posted August 23, 2012 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 Link to comment Share on other sites More sharing options...
bling8d Posted August 23, 2012 Share Posted August 23, 2012 It's a very well known website and I guess nobody here will answer me If I'd give it x) Link to comment Share on other sites More sharing options...
lionfaggot Posted December 14, 2016 Share Posted December 14, 2016 _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 dogisay 1 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