Java 身份验证弹出窗口进入后台Selenium Firefox
我已经有两周的问题了,当我在Selenium中创建一个新的Firefox驱动程序时,代理的身份验证弹出窗口立即被推到后台。硒在那里已经够不着了。你有解决这个问题的办法吗?我使用的是Selenium 3.141.5和Java1.8。Firefox版本63.0.1Java 身份验证弹出窗口进入后台Selenium Firefox,java,selenium,authentication,firefox,popupwindow,Java,Selenium,Authentication,Firefox,Popupwindow,我已经有两周的问题了,当我在Selenium中创建一个新的Firefox驱动程序时,代理的身份验证弹出窗口立即被推到后台。硒在那里已经够不着了。你有解决这个问题的办法吗?我使用的是Selenium 3.141.5和Java1.8。Firefox版本63.0.1 System.setProperty("webdriver.gecko.driver", "C:\\Program Files\\geckodriver.exe"); FirefoxOptions options = new Firefo
System.setProperty("webdriver.gecko.driver", "C:\\Program Files\\geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.setBinary("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
WebDriver driver = new FirefoxDriver(options);
try {
Alert alert = driver.switchTo().alert();
alert.sendKeys("Username" + Keys.TAB + "Password");
alert.accept();
driver.switchTo().defaultContent();
}catch (NoAlertPresentException e) {
e.printStackTrace();
}
driver.get("https://www.google.de/");
编辑:我用Firefox版本62.0.3进行了测试,一切正常。最好的方法是避免弹出窗口
FirefoxOptions options = new FirefoxOptions();
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile selenium_profile = allProfiles.getProfile("selenium_profile");
options.setProfile(selenium_profile);
options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
System.setProperty("webdriver.gecko.driver", sec_var.driver_path);
driver = new FirefoxDriver(options);
driver.manage().window().maximize();
driver.get("https://username:password@www.example.com");
但是它在Chrome中不起作用。我有着完全相同的问题,并且一直在到处寻找解决办法 以下是我到目前为止学到的:
- 使用以前保存的
保存您的凭据(@pburgr suggestion)可以实现这一目的,但它也会积累更多意外的、可能不需要的浏览器配置文件信息,如cookie、历史记录和所有信息李>自定义浏览器配置文件
- auth弹出窗口不是正常的弹出窗口,因此无法使用selenium开关\u对其进行操作
- 此外,这些类型的凭证弹出窗口无法检查,也无法编写脚本
- 另一个解决方法是使用pyAutoGui替换alt+tab并填写凭证。但这不是一个很好的解决方案,因为在弹出之前,您可能很难猜测有多少个alt+选项卡李>