How to handle browser login popup using Selenium amp; Java(如何使用 Selenium amp; 处理浏览器登录弹出窗口爪哇)
问题描述
我尝试自动化的网站有一个身份验证弹出窗口,当有人访问它时会出现.我尝试了以下代码,但 Chrome 立即在 switchTo()
行上抛出没有警报存在异常.
Firefox 似乎无法正常工作.我目前正在使用 Selenium 3.6.0 和这些浏览器的最新二进制文件.有人可以帮帮我吗?
driver = new FirefoxDriver();driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);driver.get("https://staging.brightsociety.com/");WebDriverWait 等待 = new WebDriverWait(驱动程序, 10);wait.until(ExpectedConditions.alertIsPresent());警报警报 = driver.switchTo().alert();alert.authenticateUsing(new UserAndPassword(username, password));driver.switchTo().defaultContent();
Selenium 不要通过 switchto 命令处理它,因为这是特定于浏览器而不是网站的东西.
解决方案 1:
driver.get("http://username:password@url.com");
但是这种方法的问题是,当您遍历多个页面时,弹出窗口会一次又一次地出现,这再次难以处理.
解决方案 2:(推荐)
AutoIt 脚本,下载 AutoIt 这里并找到 Authentication PopUp 的脚本 这里
The website that I am trying to automate has a authentication popup that appears when someone visits it. I tried the following code but Chrome immediately throws no alert present exception on the switchTo()
line.
Firefox does not seem to be working. I am currently using Selenium 3.6.0 with the latest binaries of these browsers. Can someone please help me out?
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("https://staging.brightsociety.com/");
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
alert.authenticateUsing(new UserAndPassword(username, password));
driver.switchTo().defaultContent();
http://staging.brightsociety.com
Selenium do not handle it by switchto command because this is something that is browser specific instead of website.
Solution 1:
driver.get("http://username:password@url.com");
But problem with this method is that as you traverse to multiple pages the popup will appear again and again which is again difficult to handle.
Solution 2: (Recommended)
AutoIt script, Download AutoIt here And Find the Script for Authentication PopUp here
这篇关于如何使用 Selenium & 处理浏览器登录弹出窗口爪哇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 Selenium & 处理浏览器登录弹出窗口爪哇
基础教程推荐
- 降序排序:Java Map 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01