我正在尝试访问网页并更新用户名和密码,但无法获取getElementById
我尝试使用谷歌和雅虎的类似代码,它们完美无缺。以下是我正在使用的代码
Sub Openurl()
Dim IE As Object
Dim IEPage As Object
Dim IEPageElement As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.navigate URL
' The below piece of code also does not work
Do Until IE.readyState = 4 'READYSTATE_COMPLETE in early binding
DoEvents
Loop
Set IEPage = IE.Document
Set IEPageElement = IEPage.getElementById(cwsUID)
If Not IEPageElement Is Nothing Then
IEPageElement.Value = UserName
Set IEPageElement = Nothing
Else
MsgBox "Coould not find the '" & UNElementID & "' element ID on the page!", vbCritical, "Element ID Error"
Exit Sub
End If
End Sub
如果此代码出现问题,请告知我们。 以下是源代码
input type="text" name="cwsUID" id="cwsUID" value="" placeholder="CWS ID" autocomplete="off" autofocus=autofocus
答案 0 :(得分:1)
虽然我不是VB专家,但我相信你必须使用引号:
IEPage.getElementById("cwsUID")
因为cwsUID
不是变量名,而是id。
答案 1 :(得分:0)
我可以使用
获取GetElementID设置IE = New InternetExplorerMedium