Kit*_*son 5 java selenium http-authentication selenium-webdriver
我有一个非常简单的selenium-webdriver脚本.我想使用webdriver进行HTTP身份验证.
脚本:
WebDriver driver = new FirefoxDriver();
driver.get("http://www.httpwatch.com/httpgallery/authentication/");
driver.findElement(By.id("displayImage")).click();
Thread.sleep(2000);
driver.switchTo().alert().sendKeys("httpwatch");
Run Code Online (Sandbox Code Playgroud)
问题:
driver.switchTo().alert().sendKeys("httpwatch");
Run Code Online (Sandbox Code Playgroud)
投
org.openqa.selenium.NoAlertPresentException:不存在警报
题:
编辑
警报具有以下方法,似乎尚未实施.
driver.switchTo().alert().authenticateUsing(new UsernameAndPassword("username","password"))
Run Code Online (Sandbox Code Playgroud)
问题是这不是一个javascript弹出窗口,因此你不能通过selenium来操作它alert().
如果AutoIt和提交URL中的凭据(最简单的选项 - 只是打开网址并单击"显示图像")不适合您,另一种方法可能是使用AutoAuth firefox插件自动提交以前保存的凭据:
当您选择让浏览器保存登录信息时,AutoAuth会自动提交HTTP身份验证对话框.(如果您已经告诉浏览器您的用户名和密码是什么,并且您已经告诉它要记住该用户名和密码,为什么不让它自动提交而不是每次都询问您?)
按照HTTP Basic Auth中的建议通过Firefox中的URL不起作用?线:
- 安装AutoAuth Firefox插件;
- 访问需要身份验证的站点.输入您的用户名和密码,并确保选择保存凭据;
- 将AutoAuth安装文件保存到硬盘驱动器:在插件页面,右键单击"添加到Firefox"和"将链接另存为";
- 将Firefox webdriver实例化如下:
FirefoxProfile firefoxProfile = new ProfilesIni().getProfile("default");
File pluginAutoAuth = new File("src/test/resources/autoauth-2.1-fx+fn.xpi");
firefoxProfile.addExtension(pluginAutoAuth);
driver = new FirefoxDriver(firefoxProfile);
Run Code Online (Sandbox Code Playgroud)
此外,以类似于AutoIt选项的方式 - 您可以使用sikuli屏幕识别和自动化工具在弹出窗口中提交凭据.
另请参阅其他想法和选项:
| 归档时间: |
|
| 查看次数: |
8152 次 |
| 最近记录: |