Scomperleur

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 ? 

Thanks for your help

Share this post


Link to post
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.


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

Thank you for your reply.

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 this post


Link to post
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.


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
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)
_IENavigate($oIE, "http://www.google.com/")
;~ _IELoadWait($oIE)

$jQuery = _InsertjQuery($oIE)

Func _InsertjQuery($oIE)
    Local $oWindow, $oHead, $oScript
    _IEPageLoadWait($oIE)
    If IsObj($oIE) Then
        $oWindow = $oIE.document.parentWindow
        $oHead = $oIE.document.getElementsByTagName('head').item(0)
        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'
            $Script = FileRead($jQueryFilePath)
            $oScript.text = $Script
            $oHead.appendChild($oScript)
            While Not (IsObj($oWindow.jQuery))
                Sleep(100)
            WEnd
            $oWindow.jQuery.noConflict()
        EndIf
        Return $oWindow.jQuery
        ConsoleWrite("Fin" & @CRLF)
    EndIf
EndFunc   ;==>_InsertjQuery

Func _IEPageLoadWait($oIE)
    Do
        Sleep(50)
    Until $oIE.readyState = 'complete' Or $oIE.readyState = 4
    Do
        Sleep(50)
    Until $oIE.document.readyState = 'complete' Or $oIE.document.readyState = 4
    Do
        Sleep(50)
    Until Not $oIE.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

 

Share this post


Link to post
Share on other sites

I can't acces to $oWindow.jQuery !

Share this post


Link to post
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.


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
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

https://en.wikipedia.org/wiki/Same-origin_policy

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

https://en.wikipedia.org/wiki/Cross-origin_resource_sharing

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 this post


Link to post
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 &= '<head>' & @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 &= '</head>' & @CRLF
$sHTML &= '<body>' & @CRLF
$sHTML &= '<script type="text/javascript">' & @CRLF
$sHTML &= '$(document).ready(function(){' & @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)
While Not (String($oIE.readyState) = "complete" Or $oIE.readyState = 4)
    Sleep(100)
WEnd
While Not (String($oIE.document.readyState) = "complete" Or $oIE.document.readyState = 4)
    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 this post


Link to post
Share on other sites

#10 ·  Posted (edited)

@Chimp, @junkew

 

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

Func _IEHeadInsertJQuery(ByRef $oObject)
    Local $oHead = $oObject.document.all.tags("HEAD").Item(0)
    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"
            .text = FileRead($jQueryFilePath)
        EndWith
        $oHead.appendChild($oScript)
        Do
            Sleep(500)
        Until IsObj($oWindow.jQuery)
        $oWindow.jQuery.noConflict()
    EndIf

    Return $oWindow.jQuery
EndFunc   ;==>_IEHeadInsertJQuery

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

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