答案 0 :(得分:1)
使用URL中的凭据(仅限基本身份验证):
Dim driver As New IEDriver
driver.Get "http://admin:admin@the-internet.herokuapp.com/basic_auth"
使用SetCredential方法(未在所有驱动程序中实现):
Dim driver As New IEDriver
driver.Get "http://the-internet.herokuapp.com/basic_auth"
Dim dlg As Alert: Set dlg = driver.SwitchToAlert(Raise:=False)
If Not dlg Is Nothing Then
dlg.SetCredentials "admin", "admin"
dlg.Accept
End If
使用WScript(仅适用于本地):
Dim driver As New IEDriver
driver.Get "http://the-internet.herokuapp.com/basic_auth"
Dim dlg As Alert: Set dlg = driver.SwitchToAlert(Raise:=False)
If Not dlg Is Nothing Then
Set wsh = CreateObject("WScript.Shell")
wsh.SendKeys "admin"
wsh.SendKeys "{TAB}"
wsh.SendKeys "admin"
dlg.Accept
End If
使用AutoIt(仅适用于本地):
Dim driver As New IEDriver
driver.Get "http://the-internet.herokuapp.com/basic_auth"
Dim dlg As Alert: Set dlg = driver.SwitchToAlert(Raise:=False)
If Not dlg Is Nothing Then
Set aut = CreateObject("AutoItX3.Control")
aut.Send "admin"
aut.Send "{TAB}"
aut.Send "admin"
dlg.Accept
End If
要使用上述示例获取最新版本的日期: https://github.com/florentbr/SeleniumBasic/releases/latest