如何使用Selenium VBA处理窗口警报以访问Intranet(Sharepoint)

时间:2015-10-02 09:37:38

标签: excel vba sharepoint selenium-ide

点击sharepoint链接时,会在身份验证下方提醒用户名& 密码

enter image description here

有没有办法处理此身份验证

1 个答案:

答案 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