vick Posted August 30, 2017 Share Posted August 30, 2017 Hi, when i use jquery in IE script stuck in loop at below code. i used jqueryIE udf. i can see it inserts jquery with script tag but it stays in below loop: how we can fix it pls? While Not(IsObj($objwindow.jQuery)) Sleep(100) WEnd Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 30, 2017 Moderators Share Posted August 30, 2017 vick, Welcome to the AutoIt forum. But please pay attention to where you post - the "Examples" section where you started this thread is clearly marked: "Do not post general support questions here". I have moved it for you, but would ask you to be more careful in future. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
vick Posted August 30, 2017 Author Share Posted August 30, 2017 (edited) hi melba, when i tried below example. it open up google page but not happened any action because it goes in loop for above code. expandcollapse popupGlobal $objAppIE, $jQuery, $jQueryFilePath = @ScriptDir & '\jquery-1.9.1.js' Global $oMyError = ObjEvent ( 'AutoIt.Error', '_MyErrFunc' ) If Not FileExists ( $jQueryFilePath ) Then InetGet ( 'http://code.jquery.com/jquery-1.9.1.js', $jQueryFilePath ) $objAppIE = ObjCreate ( 'InternetExplorer.Application' ) $objAppIE.visible = True $objAppIE.navigate ( 'http://www.google.com/' ) $jQuery = _InsertjQuery( $objAppIE ) If IsObj($jQuery) Then $jQuery(':input[id="lst-ib"]').title('Search') ; set text button Sleep(1000) ; just for see changes $jQuery(':input[id="lst-ib"]').val('autoit') ; set input text Sleep( 1000 ) ; just for see changes $jQuery(':input[name="btnK"]').submit( ) ; submit _IEPageLoadWait ( $objAppIE ) Do $aLinks = $jQuery ( '.l' ).get ( ) ; filtering by class for get only results urls. Until $aLinks.length ConsoleWrite ( '! Results Nb : ' & $aLinks.length & @Crlf ) $i=0 For $aLink In $aLinks $i+=1 ConsoleWrite ( '+ ' & $i & ' $aLink.href : ' & $aLink.href & @Crlf ) Next EndIf Func _InsertjQuery($objAppIE) Local $objWindow, $objHead, $objScript _IEPageLoadWait($objAppIE) If IsObj($objAppIE) Then $objWindow = $objAppIE.document.parentWindow $objHead = $objAppIE.document.getElementsByTagName('head').item(0) If Not IsObj($objwindow.jQuery) Then $objScript = $objAppIE.document.createElement('script') $objScript.type = 'text/javascript' $objScript.language = 'javascript' ; $objScript.defer = 'defer' $Script = FileRead($jQueryFilePath) $objScript.text = $Script $objHead.appendChild($objScript) While Not ( IsObj($objScript.jQuery)) Sleep (100) ;MsgBox(0,"","not found") WEnd $objwindow.jQuery.noConflict ( ) EndIf Return $objwindow.jQuery EndIf EndFunc ;==> _InsertjQuery ( ) Func _IEPageLoadWait ( $objAppIE ) Do Sleep ( 50 ) Until $objAppIE.readyState = 'complete' Or $objAppIE.readyState = 4 Do Sleep ( 50 ) Until $objAppIE.document.readyState = 'complete' Or $objAppIE.document.readyState = 4 Do Sleep ( 50 ) Until Not $objAppIE.busy EndFunc ;==> _IEPageLoadWait ( ) Func _MyErrFunc ( ) $HexNumber = Hex ( $oMyError.number, 8 ) If $HexNumber = 80020006 Then Return Msgbox ( 0, '', 'We intercepted a COM Error !' & @CRLF & 'Number is: ' & $HexNumber & @CRLF & 'Windescription is: ' & $oMyError.windescription & @CRLF & 'Line Number: ' & $oMyError.scriptLine & @CRLF, 3 ) Exit Endfunc ;==> _MyErrFunc ( ) Edited August 30, 2017 by Melba23 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 30, 2017 Moderators Share Posted August 30, 2017 vick, And when you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
vick Posted August 30, 2017 Author Share Posted August 30, 2017 got it sir Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted August 30, 2017 Moderators Share Posted August 30, 2017 You have a check for your jquery object: $jQuery = _InsertjQuery( $objAppIE ) If IsObj($jQuery) Then But no Else clause to handle if it does not find object. Is it getting into the If statement? Where in the code, exactly, do you find it failing? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
vick Posted August 30, 2017 Author Share Posted August 30, 2017 i have modified code like below While Not ( IsObj($objScript.jQuery)) Sleep (100) ;MsgBox(0,"","not found") WEnd so here if I remove comment from msgbox and run script i got msgbox not found so i assume that my script is waiting here in loop. Link to comment Share on other sites More sharing options...
Danp2 Posted August 30, 2017 Share Posted August 30, 2017 37 minutes ago, vick said: i have modified code like below While Not ( IsObj($objScript.jQuery)) Sleep (100) ;MsgBox(0,"","not found") WEnd so here if I remove comment from msgbox and run script i got msgbox not found so i assume that my script is waiting here in loop. I would thinks this should be checking against $objWindow.jQuery, not $objScript.jQuery. However, I couldn't get that to work either. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
vick Posted August 30, 2017 Author Share Posted August 30, 2017 i tried $objWindow.jQuery as well. but same result. Link to comment Share on other sites More sharing options...
Gianni Posted August 31, 2017 Share Posted August 31, 2017 here a way to use jquery from AutoIt within a BrowserControl (not in IE) https://www.autoitscript.com/forum/topic/185383-ie-11-automatic-using-jquery/?do=findComment&comment=1331640 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
vick Posted August 31, 2017 Author Share Posted August 31, 2017 hi sir, your example is working but hard to understand. can you try to look in my script what i am missing pls? Link to comment Share on other sites More sharing options...
Gianni Posted September 2, 2017 Share Posted September 2, 2017 Hi @vick, for what I've tested in previous topics, the problem is that in recent versions of IE, the ability to refer to javascript objects is lost, while is still possible in the "Browser Control" instead. Take a look at these topics to see some evidence on this matter: https://www.autoitscript.com/forum/topic/185387-value-of-js-variable-in-ie/ https://www.autoitscript.com/forum/topic/176731-autoit-javascript-roundtrip/ on post #13 of the first of previous topics @genius257 provided a way to bypass the proble, but it makes use of the "ExecScript" method that seems " is no longer supported" (read here: https://msdn.microsoft.com/en-us/library/ms536420(v=vs.85).aspx) even if at the moment seems that is still working. Anyway, since I've still not found another way to reference javascript without the use of the "ExecScript" method, here is a script that allows you to use jQuery within an IE browser from within AutoIt using genius257's way. You can modify also your script using the way used here to reference jQuery. expandcollapse popup; This is not an optimal example; it demonstrates ; techniques that in my opinion you should not follow. #include <ie.au3> Global $oIE = _IECreate('http://www.google.com/') ; open a browser Local $sScript_jQuery = BinaryToString(InetRead('http://code.jquery.com/jquery-1.9.1.js')) ; get jQuery listing into a variable Local $oHead = _IETagNameGetCollection($oIE, "head", 0) ; reference the Head object $objScript = $oIE.document.createElement('script') ; create a script element $objScript.type = 'text/javascript' $objScript.language = 'javascript' $objScript.text = $sScript_jQuery ; fill the script element with the jQuery listing $oHead.appendChild($objScript) ; insert the script into the page ; ...I suppose this allows to bring references from objects created in the "javascript global object" context, to the IE's context ; (from "javascript" context scope to "document" context scope) $oIE.Document.parentWindow.execScript("document.body.jQuery = jQuery;") $oIE.Document.parentWindow.execScript("document.body.eval = eval;") $ojQuery = $oIE.Document.body.jQuery ; a reference to jQuery from within AutoIt $oEval = $oIE.Document.body.eval ; a reference to eval from within AutoIt While Not (IsObj($ojQuery)) Sleep(100) WEnd MsgBox(0, "Debug", "jQuery is ready: IsObj($ojQuery) --> " & IsObj($ojQuery)) $ojQuery.noConflict() ; Relinquish jQuery's control of the $ variable MsgBox(0, "", "Hit 'OK' and the Google's logo will Fade Out using jQuery") ; You can use the $oEval variable to run jQuery $oEval("jQuery('#hplogo').fadeOut(3000);") Sleep(4000) ; give enough time to the above jQuery effect to be performed MsgBox(0, "", "Hit 'OK' now and the Google's logo will Fade In using jQuery again") ; You can also use the $ojQuery variable to run jQuery $ojQuery('#hplogo').fadeIn(3000) Sleep(4000) ; give time to jQuery to show the effect. $oEval("alert('Bye Bye from javascript');") _IEQuit($oIE) Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
vick Posted September 5, 2017 Author Share Posted September 5, 2017 yes it is working this way. can we use Xpath same way? thanks 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