问题是代码可以在我的笔记本电脑上运行但是当我将它转移到公司的PC时,代码开始显示消息框,指示getElementById无效。有没有其他方法可以在不使用sendkeys的情况下将值放在文本框中或单击按钮?
Internet Explorer的版本是相同的,但是探针的安全设置是否会影响getElementById的工作方式?
以下是visual basic的代码:
Dim HTMLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer
Private Sub CommandButton1_Click()
Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
On Error GoTo Err_Clear
MyURL = "https://www.facebook.com"
Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
MyBrowser.navigate MyURL
MyBrowser.Visible = True
Set HTMLDoc = MyBrowser.document
Do
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.document
If (HTMLDoc.getElementById("q") Is Nothing) Then
MsgBox("Textbox not detected")
Else
HTMLDoc.getElementById("email").Value = "marcomac808"
HTMLDoc.getElementById("pass").Value = ""
HTMLDoc.forms(0).submit
End If
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
waitPageEnd
End Sub