【问题标题】:How to By Pass NTLM authentication pop up while performing automation testing using Selenium web driver for Chrome browser?如何在使用 Chrome 浏览器的 Selenium Web 驱动程序执行自动化测试时绕过 NTLM 身份验证?
【发布时间】:2019-05-22 07:12:22
【问题描述】:

我使用以下 python 代码绕过 NTLM 弹出窗口。

chromedriver = webdriver.Chrome(executable_path=chromedriver_path, chrome_options=options)
chromedriver.get("https://username:password@url.com")

弹出窗口无法绕过并且仍然存在并且测试中断。

【问题讨论】:

  • 我收到 503 服务暂时不可用错误。
  • @coder123 你知道身份验证重定向到的 URL/端口吗?

标签: python-3.x selenium


【解决方案1】:

您可能会遇到域登录问题,因为浏览器将域分隔符 \ 转换为 / 并且凭据变得无效。使用编码分隔符%5C 即可。

浏览器会将https://domain\username:password@URL 转换为https://domain/username:password@URL

请求的用户编码分隔符。
https://domain\username:password@URL => https://domain%5Cusername:password@URL

【讨论】:

  • 谢谢,编码的东西救了我... 5天后 :) 尝试了除此之外的所有方法。
【解决方案2】:

正如@BhuvaneshManithis answer 的评论中提到的那样......

您需要观察 NTLM 是如何进行身份验证的。 (在 Network 下使用 chrome 中的 devTools)

找到身份验证调用后,使用该 URL!

@BhuvaneshMani's 示例:

For e.g., app url may be app.url however after hitting the url, it redirects to auth.server.url. So if you append username and password into app.url it wont work. It should be appended to auth.server.url.

所以你的代码应该是这样的:

driver = webdriver.Chrome(executable_path=chromedriver_path, chrome_options=options)
driver.get("https://username:password@auth.server.com")

或者(我发现大多数身份验证调用都是针对服务器端口的同一个 URL:port:8080/auth/login

driver.get("https://username:password@url.com:8080/auth/login")

希望对您有所帮助!

【讨论】:

    【解决方案3】:

    您还可以让 Chrome 以 当前用户 身份向 NTLM 进行身份验证,并使用与以下类似的.reg 文件:

    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\Software\Policies\Google\Chrome]
    "AuthNegotiateDelegateWhitelist"="*.companydomain.org,*.companydomain.coop"
    "AuthSchemes"="basic,digest,ntlm,negotiate"
    "AuthServerWhitelist"="*.companydomain.org,*.companydomain.coop"
    

    https://dev.to/seankilleen/quick-tip-ntlm-windows-pass-through-authentication-with-selenium-and-chromedriver-34m6

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多