Jump to content

IE_ action by click


 Share

Recommended Posts

Hey i tried to improve my Internet exsplorer skills so i tried make a login program for some sites to practice, i also wanted to try to activate a click via class and not a name and found a button on a site to practice but i dont know how to activate the button via class. i have no clue :(

#include <IE.au3>


Call    ("SignIn")


Func SignIn ()


Global $oIE = _IECreate ("https://www.die-staemme.de/")   ;Randome site, you can take a other site with a class button

Local $Username = _IEGetObjByName($oIE, "username")
Local $Password = _IEGetObjByName($oIE, "password")
Local $Login = _IEGetObjByName($oIE, "btn-login")               ;  <----- confusion idk what i am doing

_IEFormElementSetValue ($Username,"your Username")
_IEFormElementSetValue ($Password,"your Password")

_IEAction ($Login, "click")                                  ;<---- click the button
EndFunc

The Element cod for the Button is

<a class="btn-login" href="#">Login</a> == $0

If some one could help me i would be very happy thanks

 

Link to comment
Share on other sites

1 hour ago, Danp2 said:

There are numerous threads on the forum that deal with finding an element by it's class. Since this element is just a standard link, you could use _IELinkClickByText instead.

Thanks i Updated it with this

#include <IE.au3>


Call    ("SignIn")


Func SignIn ()


Global $oIE = _IECreate ("https://www.die-staemme.de/")

Local $Username = _IEGetObjByName($oIE, "username")
Local $Password = _IEGetObjByName($oIE, "password")
Local $Login = _IEGetObjByName($oIE, "btn-login")

_IEFormElementSetValue ($Username,"your Username")
_IEFormElementSetValue ($Password,"your Password")

Local $sMyString = "Login"
Local $oLinks = _IELinkGetCollection($oIE)
For $oLink In $oLinks
    Local $sLinkText = _IEPropertyGet($oLink, "innerText")
    If StringInStr($sLinkText, $sMyString) Then
        _IEAction($oLink, "click")
        ExitLoop
    EndIf
Next

EndFunc

the only problem is that the text "Login" is two times on the page, one is a text and one is a link so i think the program klicks on the first one the text... because when i take a other link like idk "Passwortwiederherstellung" it works. but with login it dosent :( i think its because of that. any solutions ?

 

thanks

 
Link to comment
Share on other sites

Just now, Danp2 said:

Why not use _IELinkClickByText  as I previously suggested? You could also try _IEFormSubmit.

I tried it but i have no clue how to cod it :( that it will work :( sry i am a noob maybee you could show me the cod

Link to comment
Share on other sites

The site uses jQuery, so a standard click doesn't work. Try this --

#include <IE.au3>


Local $oIE = _IECreate ("https://www.die-staemme.de/")
Local $jQuery = _jQuerify($oIE)

Local $Username = _IEGetObjByName($oIE, "username")
Local $Password = _IEGetObjByName($oIE, "password")

_IEFormElementSetValue ($Username,"your Username")
_IEFormElementSetValue ($Password,"your Password")

$jQuery(".btn-login").click()


; #FUNCTION# ====================================================================================================================
; Name ..........: _jQuerify
; Description ...:
; Syntax ........: _jQuerify(Byref $oIE)
; Parameters ....: $oIE                 - Object variable of an InternetExplorer.Application.
; Return values .: an object variable pointing to the jQuery library
; Author ........: Chimp
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _jQuerify(ByRef $oIE)

    Local $msie, $jsEval, $jQuery, $otherlib = False

    $msie = Execute('$oIE.document.documentMode')

    If ($msie = "") Or Number($msie) < 11 Then ; an IE version < 11
        ; create a reference to the javascript eval() function
        $oIE.document.parentWindow.setTimeout('window.eval = eval', 0)
        Do
            Sleep(250)
            $jsEval = Execute('$oIE.Document.parentwindow.eval')
        Until IsObj($jsEval)

    Else ; IE version > = 11
        ; create a reference to the javascript eval() function
        $oIE.document.parentWindow.setTimeout('document.head.eval = eval', 0)
        Do
            Sleep(250)
            $jsEval = Execute('$oIE.Document.head.eval')
        Until IsObj($jsEval)

    EndIf

    ; if jQuery is not already loaded then load it
    If $jsEval("typeof jQuery=='undefined'") Then

        ; check if the '$' (dollar) name is already in use by other library
        If $jsEval("typeof $=='function'") Then $otherlib = True

        Local $oScript = $oIE.document.createElement('script');
        $oScript.type = 'text/javascript'

        ; If you want to load jQuery from a disk file use the following statement
        ; where i.e. jquery-1.9.1.js is the file containing the jQuery source
        ; (or also use a string variable containing the whole jQuery listing)
;~ $oScript.TextContent = FileRead(@ScriptDir & "\jquery-1.9.1.js") ; <--- from a file

        ; If you want to download jQuery from the web use this statement
        $oScript.src = 'https://code.jquery.com/jquery-latest.min.js' ; <--- from an url


        $oIE.document.getElementsByTagName('head').item(0).appendChild($oScript)
        Do
            Sleep(250)
        Until $jsEval("typeof jQuery == 'function'")
    EndIf

    Do
        Sleep(250)
        $jQuery = $jsEval("jQuery")
    Until IsObj($jQuery)

    If $otherlib Then $jsEval('jQuery.noConflict();')

    Return $jQuery
EndFunc   ;==>_jQuerify

 

Link to comment
Share on other sites

8 minutes ago, Danp2 said:

The site uses jQuery, so a standard click doesn't work. Try this --

#include <IE.au3>


Local $oIE = _IECreate ("https://www.die-staemme.de/")
Local $jQuery = _jQuerify($oIE)

Local $Username = _IEGetObjByName($oIE, "username")
Local $Password = _IEGetObjByName($oIE, "password")

_IEFormElementSetValue ($Username,"your Username")
_IEFormElementSetValue ($Password,"your Password")

$jQuery(".btn-login").click()


; #FUNCTION# ====================================================================================================================
; Name ..........: _jQuerify
; Description ...:
; Syntax ........: _jQuerify(Byref $oIE)
; Parameters ....: $oIE                 - Object variable of an InternetExplorer.Application.
; Return values .: an object variable pointing to the jQuery library
; Author ........: Chimp
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _jQuerify(ByRef $oIE)

    Local $msie, $jsEval, $jQuery, $otherlib = False

    $msie = Execute('$oIE.document.documentMode')

    If ($msie = "") Or Number($msie) < 11 Then ; an IE version < 11
        ; create a reference to the javascript eval() function
        $oIE.document.parentWindow.setTimeout('window.eval = eval', 0)
        Do
            Sleep(250)
            $jsEval = Execute('$oIE.Document.parentwindow.eval')
        Until IsObj($jsEval)

    Else ; IE version > = 11
        ; create a reference to the javascript eval() function
        $oIE.document.parentWindow.setTimeout('document.head.eval = eval', 0)
        Do
            Sleep(250)
            $jsEval = Execute('$oIE.Document.head.eval')
        Until IsObj($jsEval)

    EndIf

    ; if jQuery is not already loaded then load it
    If $jsEval("typeof jQuery=='undefined'") Then

        ; check if the '$' (dollar) name is already in use by other library
        If $jsEval("typeof $=='function'") Then $otherlib = True

        Local $oScript = $oIE.document.createElement('script');
        $oScript.type = 'text/javascript'

        ; If you want to load jQuery from a disk file use the following statement
        ; where i.e. jquery-1.9.1.js is the file containing the jQuery source
        ; (or also use a string variable containing the whole jQuery listing)
;~ $oScript.TextContent = FileRead(@ScriptDir & "\jquery-1.9.1.js") ; <--- from a file

        ; If you want to download jQuery from the web use this statement
        $oScript.src = 'https://code.jquery.com/jquery-latest.min.js' ; <--- from an url


        $oIE.document.getElementsByTagName('head').item(0).appendChild($oScript)
        Do
            Sleep(250)
        Until $jsEval("typeof jQuery == 'function'")
    EndIf

    Do
        Sleep(250)
        $jQuery = $jsEval("jQuery")
    Until IsObj($jQuery)

    If $otherlib Then $jsEval('jQuery.noConflict();')

    Return $jQuery
EndFunc   ;==>_jQuerify

 

That worked great thanks, is this made by yourself or from autoit help, because its so long i need some time to understand and to addapt

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...