# IE 11 automatic using jquery

## 10 posts in this topic

Hello,

I used Autoit v3, how i can use jquery for automatic IE 11when i can select object of DOM ?

##### Share on other sites

@Scomperleur welcome to the forum. Your question is so ambiguous as to be almost unanswerable. How about explaining in more detail exactly what you're trying to select, and showing your code? Help us help you

Also, while there are plenty of people willing to assist on the AutoIt code, if your question is truly on jquery, don't be too surprised if you're directed to a more appropriate forum.

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

##### Share on other sites

I follow the tutorial in the above link but it doesn't work, how i can integrate jQuery in my page so i can use the selector, knowing that i use Internet explorer 11 and i developed in autoit v3

##### Share on other sites

Again...what have you tried? You say you have developed something in AutoIt, show us so we don't have to guess.

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

##### Share on other sites

Here's the code I have done that I have tried to integrate the libraries jquery, but it does not work, still \$oWindow.jQuery is not an object

#include <IE.au3>
Global \$oIE, \$jQuery, \$jQueryFilePath = @ScriptDir & '\jquery-1.9.1.js'
Global \$oMyError = ObjEvent('AutoIt.Error', '_MyErrFunc')

\$oIE = _IECreate()
;~ WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)

\$jQuery = _InsertjQuery(\$oIE)

Func _InsertjQuery(\$oIE)
If IsObj(\$oIE) Then
\$oWindow = \$oIE.document.parentWindow
If Not IsObj(\$oWindow.jQuery) Then
\$oScript = \$oIE.document.createElement('script')
\$oScript = \$oIE.document.createElement('script')
\$oScript.type = 'text/javascript'
\$oScript.language = 'javascript'
\$oScript.defer = 'defer'
\$oScript.text = \$Script
While Not (IsObj(\$oWindow.jQuery))
Sleep(100)
WEnd
\$oWindow.jQuery.noConflict()
EndIf
Return \$oWindow.jQuery
ConsoleWrite("Fin" & @CRLF)
EndIf
EndFunc   ;==>_InsertjQuery

Do
Sleep(50)
Do
Sleep(50)
Do
Sleep(50)
Until Not \$oIE.busy

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

##### Share on other sites

I can't acces to \$oWindow.jQuery !

##### Share on other sites

@Scomperleur you need to wait at least 24 hours before bumping your thread. We get that this is the most important thing in the world to you, but the person best able to solve the issue for you may not be online at the moment. You need to show a little patience.

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

##### Share on other sites

#8 ·  Posted (edited)

I would be surprised if this is allowed. You cannot go to a webserver and integrate it with a local JS file.

That would be a major securitybreach

however if you are in control of your webserver CORS can help

Its hard to answer further as you do not have a clear goal in your original post except for asking jquery is not working

https://www.autoitscript.com/wiki/FAQ see FAQ 31 gives you more direction probably

Edited by junkew

##### Share on other sites

not sure i've understud your question, and also I've never used jQuery, but from this quick test seems you can embed it in a browser control and use it from AutoIt.

\$oIE = ObjCreate("Shell.Explorer.2")
Local \$sHTML = ""
\$sHTML &= '<!DOCTYPE HTML><html>' & @CRLF
\$sHTML &= '<title>jQuery Hello World</title>' & @CRLF
\$sHTML &= '<meta http-equiv="X-UA-Compatible" content="IE=9" />' & @CRLF ; IE=9
\$sHTML &= '<script>var JSglobal = (1,eval)("this");</script>' & @CRLF
\$sHTML &= '<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>' & @CRLF
\$sHTML &= '<body>' & @CRLF
\$sHTML &= '<script type="text/javascript">' & @CRLF
\$sHTML &= ' \$("#msgid").html("This is Hello World by JQuery");' & @CRLF
\$sHTML &= '});' & @CRLF
\$sHTML &= '</script>' & @CRLF
\$sHTML &= 'This is Hello World by HTML' & @CRLF
\$sHTML &= '<div id="msgid">' & @CRLF
\$sHTML &= '</div>' & @CRLF
\$sHTML &= '</body>' & @CRLF
\$sHTML &= '</html>' & @CRLF

Local \$sPage = @ScriptDir & '\Page.html'
Local \$hFile = FileOpen(\$sPage, 2) ;  \$FO_OVERWRITE (2) = Write mode (erase previous contents)
FileWrite(\$hFile, \$sHTML)
FileFlush(\$hFile)
FileClose(\$hFile)

\$hGui = GUICreate("Jquery Hello world", 800, 450)
Local \$hButton1 = GUICtrlCreateButton('test 1', 650, 380, 100, 50)
Local \$hButton2 = GUICtrlCreateButton('test 2', 50, 380, 100, 50)
GUISetState(@SW_SHOW)
\$hIE = GUICtrlCreateObj(\$oIE, 10, 10, 780, 350)
\$oIE.navigate('file:///' & \$sPage)

; this waits till the document is ready to be used (portion of code from the _IELoadWait() function in IE.au3)
Sleep(100)
WEnd
Sleep(100)
WEnd

; https://msdn.microsoft.com/en-us/library/52f50e9t(v=vs.94).aspx
Local \$ohJS = \$oIE.document.parentwindow.JSglobal ; \$ohJS is a reference to the javascript Global Obj
; ---- now the javascript engine can be used in our AutoIt script using the \$ohJS reference ----

; Loop until the user exits.
While 1
Switch GUIGetMsg()
Case -3 ; \$GUI_EVENT_CLOSE
ExitLoop

Case \$hButton1

MsgBox(0, "Debug", "jQury is an obj " & IsObj(\$oIE.document.parentWindow.jQuery))

Case \$hButton2

Local \$result = \$ohJS.eval('\$("body").append("jQuery works");')
EndSwitch
WEnd
GUIDelete(\$hGui)

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

##### Share on other sites

#10 ·  Posted (edited)

Thank you for your reply, in fact I test if my site has a jquery, if not I want to add the jQuery library after the <head>  (<script type = "text / javascript" src = "http://code.jquery.com/jquery- latest.min.js "> </ script>), that's why I created the _IEHeadInsertJqueyr function presented below

Local \$oScript = \$oObject.document.createElement("script")
Local \$oWindow = \$oObject.document.parentWindow
Local \$jQueryFilePath = @ScriptDir & '\jquery-latest.min.js', \$Script
If Not FileExists(\$jQueryFilePath) Then InetGet('http://code.jquery.com/jquery-latest.min.js', \$jQueryFilePath)

If Not (IsObj(\$oWindow.jQuery)) Then
With \$oScript
.defer = True
.language = "jscript"
.type = "text/javascript"
EndWith
Do
Sleep(500)
Until IsObj(\$oWindow.jQuery)
\$oWindow.jQuery.noConflict()
EndIf

Return \$oWindow.jQuery

In order to simulate a click on an element such as an example the first <div> containing a class "btn-primary" ( elem[attr*="val"] I want to find a solution like this in autoit), but always \$oWindow.jQuery is not object.

Edited by Scomperleur