Jump to content

Auto-login website


 Share

Recommended Posts

Hey

I am creating a script that log-ins to a website and then do something more... But sometimes, when i am on an unreliable internet the login process wil sometimes fail,and i want it to automatically retry....

here is my script

Run('C:\Program Files (x86)\Opera\opera.exe')

_WinWaitActivate("Google - Opera","")

MouseClick("left",379,55,1)

Send("website.com{ENTER}")

_WinWaitActivate("BLA BLA BLA- log-in page - Opera","")

MouseClick("left",759,111,1)

Send("Email@xxxx.xxx")

Send("{TAB}")

Send("Password")

Send("{ENTER}")

$input=('C:\Program Files (x86)\Opera\opera.exe')

If ("http://www.website.com/succes - Opera") Then

_________________________________________________________________________________________

And then i can't make my script do something if succes and something else if failure....

In this case, if it goes to the succesful login page do something and if it goes to the unsuccesful do something else...

I dont know how to make the endif works... my problem is that the script should continue even if it goes to the unsuccesful site...

Hope you understand and can help me.

Kind Regards

ZachDoom

Link to comment
Share on other sites

I don't know the "_WinWaitActivate" function, but I assume it returns the hWnd of Opera use it with WinGetTitle(). If the title still indicates some sort of login page you know the login failed, so you can do something like this:

Global $hWnd, $sTitle

Run('C:\Program Files (x86)\Opera\opera.exe')
_WinWaitActivate("Google - Opera","")
MouseClick("left",379,55,1)
Send("website.com{ENTER}")

$hWnd = _WinWaitActivate("BLA BLA BLA- log-in page - Opera","")
MouseClick("left",759,111,1)

Send("Email@xxxx.xxx")
Send("{TAB}")
Send("Password")
Send("{ENTER}")

Sleep(3000) ;try what works for you here.

$sTitle = WinGetTitle($hWnd)
If StringInStr($sTitle,"log-in") Or StringInStr($sTitle,"login") Then
    ;code to run if login failed, like retry.
Else
    ;code to run if login was successfull
EndIf

I don't expect that to work, but it should demonstrate the idea.

In any case I strongly reccomend using something else than Opera for this.

The WinHttp.au3 UDF will allow you to interact with the page without using a browser but can be confusing at first.

If you want a browser it would be much easier to use IE, as every windows computer has it and AutoIt comes with the great IE.au3 UDF.

Link to comment
Share on other sites

I don't fully understand what you tryed either , so I just continued tryed something, does this do what you want it to do?

Run('C:\Program Files (x86)\Opera\opera.exe')
_WinWaitActivate("Google - Opera","")
MouseClick("left",379,55,1)
Send("website.com{ENTER}")

if WinActive("BLA BLA BLA- log in page - Opera") Then   ; if it is on the login page, then login
    login()
ElseIf  WinActive("Login succes - Opera") Then; If it's on the succes page, then exit script
    Exit
Else                                            ; if none of both, go back to the login page
    MouseClick("left",379,55,1)
    Send("website.com{ENTER}") 
EndIf

Func login()
        MouseClick("left",759,111,1)
        Send("Email@xxxx.xxx")
        Send("{TAB}")
        Send("Password")
        Send("{ENTER}")
EndFunc

If not, try explaining better.

Link to comment
Share on other sites

Well, both of you thank you... i am close to figuring out with your help and a little tweaking :) But a simple question, how do i insert a delay between to steps?

And secondly, if you know a good winhttp.au3 tutorial, would you send it?

Link to comment
Share on other sites

The does have a very nice helpfile that comes with the package, but I can't help you with a tutorial on the workings of HTTP itsself as I learned by trail and error. (I used the Firefox addon "Live HTTP Headers" to see what is usually send and received and then just tried to copy that.)

A hidden instance of IE is a nice in-between solution although a little slower than WinHttp. It's nice to be able to write a script for a visible browser. (easy debugging) and then just adding the hidden flag.

If you do want to learn about WinHTTP, just check the helpfile for examples. If you're stuck you can always come back here.

Link to comment
Share on other sites

Well, both of you thank you... i am close to figuring out with your help and a little tweaking :) But a simple question, how do i insert a delay between to steps?

And secondly, if you know a good winhttp.au3 tutorial, would you send it?

Sleep(delay in ms)
Link to comment
Share on other sites

  • 1 year later...
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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