4

I found this script online, I edited most of it.

It is able to enter username, and password on its down but it is not able to click login.

please help me fix Here is login forum.

http://desistream.tv/en/index.shtml

Here is Script currently it is in IE but I will need to change it open in Google Chrome.

WScript.Quit Main

Function Main
  Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
  IE.Visible = True
  IE.Navigate "http://desistream.tv/en/index.shtml"
  Wait IE
  With IE.Document
    .getElementByID("login_username").value = "myusername"
    .getElementByID("login_password").value = "mypassword"
    .getElementByID("form").submit
  End With
End Function

Sub Wait(IE)
  Do
    WScript.Sleep 500
  Loop While IE.ReadyState < 4 And IE.Busy 
  Do
    WScript.Sleep 500
  Loop While IE.ReadyState < 4 And IE.Busy 
End Sub

Sub IE_OnQuit
  On Error Resume Next
  WScript.StdErr.WriteLine "IE closed before script finished."
  WScript.Quit
End Sub
Mowgli
  • 3,422
  • 21
  • 64
  • 88

2 Answers2

3

Here is...

Call Main

Function Main
    Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
    IE.Visible = True
    IE.Navigate "http://desistream.tv/en/index.shtml"
    Wait IE
    With IE.Document
        .getElementByID("username").value = "myusername"
        .getElementByID("pass").value = "mypassword"
        .getElementsByName("frmLogin")(0).Submit
    End With
End Function

Sub Wait(IE)
  Do
    WScript.Sleep 500
  Loop While IE.ReadyState < 4 And IE.Busy
End Sub
Panayot Karabakalov
  • 3,109
  • 3
  • 19
  • 28
  • Thanks, how can I add condition if account is already logged in? because it is prompting error. – Mowgli Jan 08 '13 at 19:34
  • 1
    Glad to see that I not forget everything as my last web scripting was about 10 years ago :) The site rules not allow multiple questions in one topic, so you can open new topic if you like, and probably will get better reply, but my short reply is - just find an html element that's available on that page only when you logged-in and check for existence of that element, and to start login only if needs. – Panayot Karabakalov Jan 08 '13 at 20:17
  • As for doing so in Google Chrome, you can't without automation extensions. See this thread [link](http://stackoverflow.com/questions/87911/tool-framework-for-automated-web-app-testing-in-google-chrome-browser), or just google for "google chrome browser automation". – Panayot Karabakalov Jan 08 '13 at 20:18
1

If you look at the page source, you'll see that the actual <form> tag is called frmLogin, not login.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964