Java 身份验证弹出窗口进入后台Selenium Firefox

Java 身份验证弹出窗口进入后台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

我已经有两周的问题了,当我在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 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进行了测试,一切正常。

最好的方法是避免弹出窗口

  • 点击Win+R,运行“firefox-p”并创建新的配置文件(我们称之为selenium\u配置文件)
  • 在Seleniu配置文件中运行Firefox,登录到代理并将您的凭据保存到Firefox
  • 使用自定义配置文件,有我的设置:

    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();
    
  • 使用自定义浏览器配置文件,您可以使用几乎任何设置修改、导入的证书(以避免出现另一个身份验证弹出窗口)、使用扩展

    使用URL中的发送凭据可以避免出现基本身份验证弹出窗口:

    driver.get("https://username:password@www.example.com");
    

    但是它在Chrome中不起作用。

    我有着完全相同的问题,并且一直在到处寻找解决办法

    以下是我到目前为止学到的:

    • 使用以前保存的
      自定义浏览器配置文件
      保存您的凭据(@pburgr suggestion)可以实现这一目的,但它也会积累更多意外的、可能不需要的浏览器配置文件信息,如cookie、历史记录和所有信息
    • auth弹出窗口不是正常的弹出窗口,因此无法使用selenium开关\u对其进行操作
    • 此外,这些类型的凭证弹出窗口无法检查,也无法编写脚本
    • 另一个解决方法是使用pyAutoGui替换alt+tab并填写凭证。但这不是一个很好的解决方案,因为在弹出之前,您可能很难猜测有多少个alt+选项卡
    底线:最有希望的方法是加载一个新的干净的浏览器配置文件,通过添加这样的凭据(我不知道如何更新,也不知道是否可行)来更新此配置文件,然后在会话结束时丢弃此配置文件