vick

jquery in IE

13 posts in this topic

#1 ·  Posted

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

Share this post


Link to post
Share on other sites



#2 ·  Posted

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (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.

Global $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 by Melba23

Share this post


Link to post
Share on other sites

#4 ·  Posted

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted

got it sir

Share this post


Link to post
Share on other sites

#6 ·  Posted

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?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#7 ·  Posted

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.

Share this post


Link to post
Share on other sites

#8 ·  Posted

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.

Share this post


Link to post
Share on other sites

#9 ·  Posted

i tried  $objWindow.jQuery as well. but same result.

Share this post


Link to post
Share on other sites

#11 ·  Posted

hi sir,

 

your example is working but hard to understand. can you try to look in my script what i am missing pls?

Share this post


Link to post
Share on other sites

#12 ·  Posted

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.

; 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)

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#13 ·  Posted

yes it is working this way. can we use Xpath same way?

thanks

 

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