如何使用VBS在新IE选项卡中打开URL?

时间:2013-12-17 10:46:18

标签: internet-explorer google-chrome vbscript

我想使用VBS打开一些URL,并且需要直接输入登录凭据。 PFB我的代码:

    WScript.Quit Main

    Function Main
      Set IE = WScript.CreateObject("InternetExplorer.Application")
      IE.Visible = True
      IE.Navigate "https://accounts.google.com/ServiceLogin?hl=en&continue=https://www.google.co.in/%3Fgws_rd%3Dcr%26ei%3DoSiwUqWmO8LvkQXGhIGoBg"
      Wait IE
      With IE.Document
        .get

ElementByID("Email").value = "xyz@gmail.com"
    .getElementByID("Passwd").value = "123"
  End With
  IE.Navigate "https://accounts.google.com/ServiceLogin?hl=en&continue=https://www.google.co.in/%3Fgws_rd%3Dcr%26ei%3DoSiwUqWmO8LvkQXGhIGoBg"
  Wait IE
  With IE.Document
    .getElementByID("Email").value = "abc@gmail.com"
    .getElementByID("Passwd").value = "12345"
  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. 如何确保此链接在同一窗口中打开但不同的标签?
  2. 我尝试了几件事,但无法编写代码,以便通过代码点击登录按钮。有办法吗?
  3. 我在一些地方读到VBS不能与Chrome合作。但坦率地说,IE使用起来不是很方便。那么在某些方面我可以在Chrome中获得类似的结果吗?
  4. 第一次尝试VBS,所以我可能会觉得有点幼稚! 请耐心! :)

    提前致谢! :)

0 个答案:

没有答案