trnew Posted April 21, 2013 Posted April 21, 2013 For some reason, I didn't find anything about this function in the autoit forum (if there is anything, please leave a link).I'm interested in its usage, as the example for this function doesn't really help me.I want something like this :#codeLocal $sText = ControlGetText("[CLASS:IEFrame]", "", 0)MsgBox(0, "ControlGetText Example", "The control text is: " & $sText)#endofcodeHere, one problem might be the ID (cause it's not "Edit1" and I used 0 because I thought it would work this way, and it kinda did, but the msgbox returned only some text, while I wanted it to return all text of the control, like all text of the webpage part - it is important for me to get the text using controlgettext).Can you help me get the code right?( also I'm quite confused about the controlgettext, because it says I have to write the "The title of the window to access.", I don't know what I should use for CLASS : either IEFrame -> but the msgbox returns only a bit of info, either Internet Explorer_Server which is the class of the control, but that doesn't work, though I think this would have the msgbox display all text in the webpage, but this would be the CLASS of a control, not of a window and maybe this is why it doesn't work->if there is a function which I can use for getting the text of a control, please let me know. Again, I'm interested in getting all text in the webpage part and I don't know what's the right CLASS to use for this to work)Thank you very much for your help.
water Posted April 21, 2013 Posted April 21, 2013 To get the content of a webpage I suggest to have a look at the IE UDF that comes with AutoIt. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
trnew Posted April 21, 2013 Author Posted April 21, 2013 (edited) From the IE.au3 I think this is the code I need ( but I still do something wrong..I don't know how I should use the parameters so that controlgettext will work -like in the example provided): The example: ; Parameters ....: $hWin - HWND of a Internet Explorer_Server1 control obtained for example: ; $hwnd = ControlGetHandle("MyApp","","Internet Explorer_Server1") How come "MyApp" is the title?I mean shouldn't it be something like "[CLASS:Internet Explorer_Server1]" or "AutoIt Forums - Windows Internet Explorer" or "controlgettext - General Help and Support - AutoIt Forums - Windows Internet Explore" ? ( I got those values by using Autoit Window Info) The code (I will copy only the part of the code that I think is useful, I didn't delete the rest of IE.au3 content and no, I'm not testing this in the original IE.au3) : $hwnd = ControlGetText("[CLASS:Internet Explorer_Server1]","", "Internet Explorer_Server1") MsgBox(0, "ControlGetText Example", "The control text is: " & $hwnd) Func __IEControlGetObjFromHWND(ByRef $hWin) ; The code assumes CoInitialize() succeeded due to the number of different ; yet successful return values it has. DllCall("ole32.dll", "long", "CoInitialize", "ptr", 0) If @error Then Return SetError(2, @error, 0) Local Const $WM_HTML_GETOBJECT = __IERegisterWindowMessage("WM_HTML_GETOBJECT") Local Const $SMTO_ABORTIFHUNG = 0x0002 Local $lResult __IESendMessageTimeout($hWin, $WM_HTML_GETOBJECT, 0, 0, $SMTO_ABORTIFHUNG, 1000, $lResult) Local $typUUID = DllStructCreate("int;short;short;byte[8]") DllStructSetData($typUUID, 1, 0x626FC520) DllStructSetData($typUUID, 2, 0xA41E) DllStructSetData($typUUID, 3, 0x11CF) DllStructSetData($typUUID, 4, 0xA7, 1) DllStructSetData($typUUID, 4, 0x31, 2) DllStructSetData($typUUID, 4, 0x0, 3) DllStructSetData($typUUID, 4, 0xA0, 4) DllStructSetData($typUUID, 4, 0xC9, 5) DllStructSetData($typUUID, 4, 0x8, 6) DllStructSetData($typUUID, 4, 0x26, 7) DllStructSetData($typUUID, 4, 0x37, 8) Local $aRet = DllCall("oleacc.dll", "long", "ObjectFromLresult", "lresult", $lResult, "struct*", $typUUID, _ "wparam", 0, "idispatch*", 0) If @error Then Return SetError(3, @error, 0) If IsObj($aRet[4]) Then Local $oIE = $aRet[4] .Script() ; $oIE is now a valid IDispatch object Return $oIE.document.parentwindow Else Return SetError(1, $aRet[0], 0) EndIf EndFunc ;==>__IEControlGetObjFromHWND I apperciate your help. -- And what's with CoInitialize() ?Shouldn't this function be in the file or #included? -- A really useful UDF would be : _IEFormElementGetValue But I'll have to test a bit... Edited April 21, 2013 by trnew
water Posted April 21, 2013 Posted April 21, 2013 I really don't get what you try to do. Can you please post a screenshot, maybe we get an idea? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
kylomas Posted April 21, 2013 Posted April 21, 2013 trnew, When water referred you to the IE* functions I think he had something more like this in mind (return all text from this thread) expandcollapse popup#include <IE.au3> _IEErrorHandlerRegister('IE_ERR') Local $oIE = _IECreate('http://www.autoitscript.com/forum/topic/150182-controlgettext/', 0, 0, 1, 0) ConsoleWrite(_get_text($oIE) & @LF) _IEErrorHandlerDeRegister() Func _get_text($oIE) Local $ret_str Local $odivs = _IETagNameGetCollection($oIE, 'div') For $odiv In $odivs If $odiv.classname == 'post entry-content ' Then $ret_str &= $odiv.innerText & @LF Next Return $ret_str EndFunc ;==>_get_text Func IE_ERR() ; Important: the error object variable MUST be named $oIEErrorHandler Local $ErrorScriptline = $oIEErrorHandler.scriptline Local $ErrorNumber = $oIEErrorHandler.number Local $ErrorNumberHex = Hex($oIEErrorHandler.number, 8) Local $ErrorDescription = StringStripWS($oIEErrorHandler.description, 2) Local $ErrorWinDescription = StringStripWS($oIEErrorHandler.WinDescription, 2) Local $ErrorSource = $oIEErrorHandler.Source Local $ErrorHelpFile = $oIEErrorHandler.HelpFile Local $ErrorHelpContext = $oIEErrorHandler.HelpContext Local $ErrorLastDllError = $oIEErrorHandler.LastDllError Local $ErrorOutput = "" $ErrorOutput &= "--> COM Error Encountered in " & @ScriptName & @CR $ErrorOutput &= "----> $ErrorScriptline = " & $ErrorScriptline & @CR $ErrorOutput &= "----> $ErrorNumberHex = " & $ErrorNumberHex & @CR $ErrorOutput &= "----> $ErrorNumber = " & $ErrorNumber & @CR $ErrorOutput &= "----> $ErrorWinDescription = " & $ErrorWinDescription & @CR $ErrorOutput &= "----> $ErrorDescription = " & $ErrorDescription & @CR $ErrorOutput &= "----> $ErrorSource = " & $ErrorSource & @CR $ErrorOutput &= "----> $ErrorHelpFile = " & $ErrorHelpFile & @CR $ErrorOutput &= "----> $ErrorHelpContext = " & $ErrorHelpContext & @CR $ErrorOutput &= "----> $ErrorLastDllError = " & $ErrorLastDllError MsgBox(0, "COM Error", $ErrorOutput) SetError(1) Return EndFunc ;==>IE_ERR That seems to be what you are asking with this Again, I'm interested in getting all text in the webpage part and I don't know what's the right CLASS to use for this to work) Not sure what you mean by this all text of the webpage part - it is important for me to get the text using controlgettext). kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
trnew Posted April 21, 2013 Author Posted April 21, 2013 Ok.I'll upload a .swf file.I open the .swf file with internet explorer (Allow block content ...) and it plays my movie in which I have a string of chars and numbers. I want something like an IE function that can search what I want through that IE page and then msgbox me "Value found".For example I search for "num" (without quotes) a msgbox will appaer saying "Value found". Well, I guess this won't work.I can't upload .swf files (for personal security I guess).I'll change the extension to .txt and after you donwload it you can change it back to .swf so it will work.Please let me know if this is not allowed..though I really wanted to know how this kind of search would be performed.find.txt
trnew Posted April 21, 2013 Author Posted April 21, 2013 (edited) Wait.Sorry I guess that couldn't be possible because of the image-like layers...I have a better file example ( top left side "asdds" is static text - don't think I could find this. top right side "sadqs" is dynamic text. bottom right side "asdasd" is input text ).I'm interested if I could find the input text and dynamic text ( there's not relation between them, but they are selectable and I think this way I could search for them and find them ). Again, I changed the .swf extension to .txt.. Edit : Thanks for the example kylomas.I'm really sorry I confused you..goodexample.txt Edited April 21, 2013 by trnew
trnew Posted April 21, 2013 Author Posted April 21, 2013 @kylomasOnce i'm presented with a script I try to see how it worksDidn't have time to check your script then ( i just got to it now), but when I tested it, it didn't work, nothing was displayed(or I don't know what it actually does).It's complicated and it's to be expected as I requested help with something that it's not that easy.Could you please explain how it works? Especially the part with "Return $ret_str" .In what maner does it return the text?( mabybe it's just me, but I think it would display only encountered errors , because of that MsgBox(0, "COM Error", $ErrorOutput) function) I modified the code (now it's been dimmed to my view of things..cause I don't know how your code works... amazigly the script survived my cutting after I modifed it to get all the text from this webpage through a msgbox):#include <IE.au3> Local $oIE = _IECreate('http://www.autoitscript.com/forum/topic/150182-controlgettext/', 0, 0, 1, 0) ConsoleWrite(_get_text($oIE) & @LF) Func _get_text($oIE) Local $ret_str Local $odivs = _IETagNameGetCollection($oIE, 'div') For $odiv In $odivs If $odiv.classname == 'post entry-content ' Then $ret_str &= $odiv.innerText & @LF Next MsgBox(0, "thread", $ret_str) EndFunc ;==>_get_text Or would it be like this : expandcollapse popup#include <IE.au3> _IEErrorHandlerRegister('IE_ERR') Local $oIE = _IECreate('http://www.autoitscript.com/forum/topic/150182-controlgettext/', 0, 0, 1, 0) ConsoleWrite(_get_text($oIE) & @LF) _IEErrorHandlerDeRegister() Func _get_text($oIE) Local $ret_str Local $odivs = _IETagNameGetCollection($oIE, 'div') For $odiv In $odivs If $odiv.classname == 'post entry-content ' Then $ret_str &= $odiv.innerText & @LF Next MsgBox(0, "thread", $ret_str) EndFunc ;==>_get_text Func IE_ERR() ; Important: the error object variable MUST be named $oIEErrorHandler Local $ErrorScriptline = $oIEErrorHandler.scriptline Local $ErrorNumber = $oIEErrorHandler.number Local $ErrorNumberHex = Hex($oIEErrorHandler.number, 8) Local $ErrorDescription = StringStripWS($oIEErrorHandler.description, 2) Local $ErrorWinDescription = StringStripWS($oIEErrorHandler.WinDescription, 2) Local $ErrorSource = $oIEErrorHandler.Source Local $ErrorHelpFile = $oIEErrorHandler.HelpFile Local $ErrorHelpContext = $oIEErrorHandler.HelpContext Local $ErrorLastDllError = $oIEErrorHandler.LastDllError Local $ErrorOutput = "" $ErrorOutput &= "--> COM Error Encountered in " & @ScriptName & @CR $ErrorOutput &= "----> $ErrorScriptline = " & $ErrorScriptline & @CR $ErrorOutput &= "----> $ErrorNumberHex = " & $ErrorNumberHex & @CR $ErrorOutput &= "----> $ErrorNumber = " & $ErrorNumber & @CR $ErrorOutput &= "----> $ErrorWinDescription = " & $ErrorWinDescription & @CR $ErrorOutput &= "----> $ErrorDescription = " & $ErrorDescription & @CR $ErrorOutput &= "----> $ErrorSource = " & $ErrorSource & @CR $ErrorOutput &= "----> $ErrorHelpFile = " & $ErrorHelpFile & @CR $ErrorOutput &= "----> $ErrorHelpContext = " & $ErrorHelpContext & @CR $ErrorOutput &= "----> $ErrorLastDllError = " & $ErrorLastDllError Return $ErrorOutput SetError(1) Return EndFunc ;==>IE_ERR What I want to know is the difference between what my code does and yours (which of course it's better, but I don't understand it).If I'm to understand those UDFs I got to ask a lot of questions..I'm sorry for bothering you, so thinking about this, do you know where I can find information about those .innertext, .classname etc things?I think it would be useful if I start with learning how to use those.
kylomas Posted April 21, 2013 Posted April 21, 2013 trnew,but when I tested it, it didn't work, nothing was displayedThis is probably my fault. The consolewrite displays the returned value ($ret_str) in the lower SCITE pane. Are you using the FULL SCITE editor?"Return $ret_str"In short, this sends back to whatever called the function the contents of $ret_str. The "Functions" section of the Help file might interest you. What I want to know is the difference between what my code does and yoursIf you are referring to the original code that you posted, you are operating on a control directly whereas I am interfacing with the IE object. As to which is better, I guess that depend on what you are trying to do. I have never used code similar to yours and have never had a need to operate on a control. Maybe one of the heavy weights has an opinion.do you know where I can find information about those .innertext, .classname etc things?The simple, smart ass reply is MSDN. Unfortunately it's also true. One way that I found helpfull for me to get through that pile of spaghetti is to search on a term and start reading all of the related items (note - I have NO Windows programming experience so this is all a crap shoot for me).One last comment, given your relative inexperience with Autoit (shows from the questions you ask) you will be well served reading the Help documentation thoroughly. You will also find that mostly anything can be solved using the forum and search.(...Hmmm..this seems like a long winded way of saying nothing...)Good Luck,kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
trnew Posted April 22, 2013 Author Posted April 22, 2013 1) No, I am sorry ...It was actually my fault.The code worked really well and the console displayed it well.Yes, I'm using the full version of Scite editor ( ithought it would be good to get so I don't have a surprise later like "oops why doesn't this function work ?!" ) 2) Thanks for clearing up things and yes, I don't really have experience in autoit scripting ( more like one week experience ).So I thought at first I should take a look at the help file ...I will do this in the near future I hope.And I decided to take a longer look at IE functions.I will just exercise now and, if you/anybody would want to help me with what i'll be testing, i'd really appreciate it. I like your code..but I tried to make things different a bit ( just to exercise ).So I thought about displaying all the coments of this webpage in an IE_embedded object ( I know I can do this just by using IEnavigate, but I don't want this because ..it's the purpose of my exercise to do this my way ).For this I thought I should use _IEDocInsertText (maybe it's not the best way, but this is what I think to be fit -more for exercising but anyway - and if this can be done by using this function I want to know how) and insert the text you got by running your script - specifically the _get_text($oIE) function - into the IE_embedded object.So, I wrote the code and..as you probably guessed, it didn't work.. I don't know what my mistakes are ( myabe the for...next doesn't work well if I use it like I used it in the code below, or maybe I got some varaible wrong ). expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <IE.au3> _IEErrorHandlerRegister('IE_ERR') Global $oIE = _IECreate('http://www.autoitscript.com/forum/topic/150182-controlgettext/', 0, 0, 1, 0) $obj = _IECreateEmbedded() GUICreate("Embedded Test", 640, 580, _ (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _ $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN) GUICtrlCreateObj($obj, 10, 40, 600, 360) GUISetState() _get_text($oIE) While 1 Select Case GUIGetMsg() = $GUI_EVENT_CLOSE Exit EndSelect WEnd GUIDelete() _IEErrorHandlerDeRegister() Func _get_text($oIE) Global $ret_str Global $odivs = _IETagNameGetCollection($oIE, 'div') For $odiv In $odivs If $odiv.classname == 'post entry-content ' Then $ret_str &= $odiv.innerText & @LF Next _IEDocInsertText($obj, $ret_str) EndFunc ;==>_get_text Func IE_ERR() ; Important: the error object variable MUST be named $oIEErrorHandler Local $ErrorScriptline = $oIEErrorHandler.scriptline Local $ErrorNumber = $oIEErrorHandler.number Local $ErrorNumberHex = Hex($oIEErrorHandler.number, 8) Local $ErrorDescription = StringStripWS($oIEErrorHandler.description, 2) Local $ErrorWinDescription = StringStripWS($oIEErrorHandler.WinDescription, 2) Local $ErrorSource = $oIEErrorHandler.Source Local $ErrorHelpFile = $oIEErrorHandler.HelpFile Local $ErrorHelpContext = $oIEErrorHandler.HelpContext Local $ErrorLastDllError = $oIEErrorHandler.LastDllError Local $ErrorOutput = "" $ErrorOutput &= "--> COM Error Encountered in " & @ScriptName & @CR $ErrorOutput &= "----> $ErrorScriptline = " & $ErrorScriptline & @CR $ErrorOutput &= "----> $ErrorNumberHex = " & $ErrorNumberHex & @CR $ErrorOutput &= "----> $ErrorNumber = " & $ErrorNumber & @CR $ErrorOutput &= "----> $ErrorWinDescription = " & $ErrorWinDescription & @CR $ErrorOutput &= "----> $ErrorDescription = " & $ErrorDescription & @CR $ErrorOutput &= "----> $ErrorSource = " & $ErrorSource & @CR $ErrorOutput &= "----> $ErrorHelpFile = " & $ErrorHelpFile & @CR $ErrorOutput &= "----> $ErrorHelpContext = " & $ErrorHelpContext & @CR $ErrorOutput &= "----> $ErrorLastDllError = " & $ErrorLastDllError MsgBox(0, "COM Error", $ErrorOutput) SetError(1) Return EndFunc ;==>IE_ERR Thanks for your help and I hope I'm not bothering anyone with my help requests.
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