Internet explorer 使用WebDriver通过IE身份验证

Internet explorer 使用WebDriver通过IE身份验证,internet-explorer,python-2.7,authentication,selenium-webdriver,Internet Explorer,Python 2.7,Authentication,Selenium Webdriver,我想知道是否有人使用带有Python的Webdriver来导航IE中弹出的用户身份验证窗口 有人建议我使用AutoIT,但我希望我的解决方案严格遵循Python 我尝试了python ntlm,但在运行下面的脚本时,遇到了一个需要授权的错误: import urllib2 from ntlm import HTTPNtlmAuthHandler user = r'userName' password = 'password' url = 'url goes here' passman =

我想知道是否有人使用带有Python的Webdriver来导航IE中弹出的用户身份验证窗口

有人建议我使用
AutoIT
,但我希望我的解决方案严格遵循Python

我尝试了
python ntlm
,但在运行下面的脚本时,遇到了一个需要授权的错误:

import urllib2
from ntlm import HTTPNtlmAuthHandler

user = r'userName'
password = 'password'

url = 'url goes here'

passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, url, user, password)

# Create the NTLM Authentication Handler
auth_NTLM = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(passman)

# Create and install the opener
opener = urllib2.build_opener(auth_NTLM)
urllib2.install_opener(opener)

# retrieve the result
response = urllib2.urlopen(url)
print response.read()
我想知道其他人是怎么处理的? 下面是我的webdriver脚本,我在其中尝试使用
窗口\u句柄
调用:

    def test_ie_navigation(self):
    user = 'userName'
    password = 'passWord'

    driver = self.driver
    driver.get("url I am going to")
    aw = driver.window_handles
    auth_window = driver.switch_to.window(aw[1])
    auth_window.sendKeys(user)
    auth_window.sendKeys(Keys.TAB)
    auth_window.sendKeys(password)
    auth_window.snedKeys(Keys.ENTER)

请尝试以下代码:

def test_ie_navigation(self):
user = 'userName'
password = 'passWord'

driver = self.driver
driver.get("http://<USERNAME>:<PASSWORD>@<url I am going to (Note: Don't give http/https here as it is already appended in the beginning)>") # e.g. driver.get("http://<USERNAME>:<PASSWORD>@google.co.in")
aw = driver.window_handles
auth_window = driver.switch_to.window(aw[1])
auth_window.sendKeys(user)
auth_window.sendKeys(Keys.TAB)
auth_window.sendKeys(password)
auth_window.sendKeys(Keys.ENTER)
def测试ie_导航(自):
用户='userName'
密码='password'
driver=self.driver

get(“http://:@我遇到了同样的问题,并使用解决了它,所以我的代码仍然是纯python

import autoit
autoit.win_wait_active("Windows Security")
autoit.send(user['username'])
autoit.send("{TAB}")
autoit.send(user['password'])
autoit.send("{ENTER}")

以上是我在当前设置(Python 3、Internet Explorer 11、Windows 8.1计算机)上运行的代码.

感谢您的回复,但是这不适用于IE,因为它是浏览器的红头发继子,它适用于Chrome和Firefox。我们需要对这三种浏览器进行测试,这就是为什么我试图找到一个IE特定的解决方案。非常感谢,我将尝试一下,这将使我们的测试运行得更快,因为我们目前是g正在向Web服务器发送一个外部脚本以运行。不过这应该可以做到。我正在尝试安装此软件包,并不断收到[Error 193]%1不是有效的Win32应用程序。我正在尝试将其安装在64位Windows 8.1系统上。我已安装AutoIT,并已注册了32位和64位AutoItX3 dll文件。我在此处还缺少什么?如果您使用virtualenv并在虚拟环境上安装python包,可能会有所帮助。安装应易于使用“pip安装pyautoit"命令。另外,您不需要安装AutoIt,我的也可以在没有它的情况下工作。在Windows计算机上使用virtualenv有什么好处?不像在linux或mac安装时那样,我会干扰计算机上已安装的python版本。使用virtualenv将隔离大多数例如,在这种情况下,如果您使用virtualenv,我相信您不会遇到像现在这样的错误(即,[Error 193]%1)。