2013-01-09 92 views
1

由於某種原因,下面的VBS像IE 8中的魅力,但在我的筆記本電腦上的IE9上 我在.getElement獲得Object Required。IE 9錯誤getElementbyId:對象需要

我該如何解決此問題。

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 

編輯

這是我在JScript

var WshShell = WScript.CreateObject("WScript.Shell"); 
WshShell.Run("Chrome www.desistream.tv", 10, true); 
WScript.Sleep(500); 
+0

還沒有見過像永遠VBS。爲什麼不用JavaScript重新做呢,我肯定會更加兼容。 – elclanrs

+0

我不知道如何:(我試過 – Mowgli

+0

你想用這段代碼做什麼? – elclanrs

回答

1

走到這一步,你需要使用正確的名稱。你給的名稱是Name屬性,而不是ID,所以:

.getElementByID("login_username").value = "myuser" 
.getElementByID("login_password").value = "mypass" 

應該是:

.getElementByID("username").Value = "myuser" 
.getElementByID("pass").Value = "mypass" 
+0

不,這不是問題,我已經嘗試過了,而且我已經在IE8上工作了。 – Mowgli

+0

好吧,我用ie9測試了我的例子,它工作。 – Fionnuala

+0

讓我試着用兼容模式和你的代碼,但看起來問題是與兼容模式開始。 – Mowgli