我们可以在AutoHotKey中执行getElementByID吗?

时间:2013-01-09 21:01:59

标签: dom vbscript autohotkey porting

我有这个VBS代码它就像一个魅力,但由于Chrome不支持VB脚本。

我需要找到autohotkey的替代品。

有人可以帮助我将此代码转换为AutoHotKey(如果不仅仅是部分内容)。

Here is part of code我需要在AutoHotKey中执行

  With IE.Document
    .getElementByID("login_username").value = "myuser"
    .getElementByID("login_password").value = "mypass"
    .getElementByID("frmLogin").submit
  End With

以下是完整代码

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 = "myuser"
    .getElementByID("login_password").value = "mypass"
    .getElementByID("frmLogin").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

1 个答案:

答案 0 :(得分:3)

#SingleInstance, force
#NoEnv
OnExit, ExitSub

IE := ComObjCreate("InternetExplorer.Application")
IE.Visible := true
IE.Navigate("http://desistream.tv/en/index.shtml")

Wait(IE)

pDoc := IE.document

pDoc.getElementByID("username").value := "myuser"
pDoc.getElementByID("pass").value := "mypass"
pDoc.all.frmLogin.submit()

return


+Esc::  ;shift + esc
ExitSub:
try
        IE.Quit
        IE := ""
Exitapp

Wait(IE) {
while IE.readyState!=4 || IE.document.readyState != "complete" || IE.busy
 sleep 10
}

我认为这就是

希望有所帮助