使用Selenium和Firefox浏览器版本35的2.53.1版本以及此脚本:
package no.mine;
import java.net.MalformedURLException;
import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.remote.*;
import java.util.concurrent.TimeUnit;
public class SeleniumAdmin {
private static WebDriver driver = null;
public static void main(String[] args) {
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffProfile = profile.getProfile("MagnusQA");
ffProfile.setAcceptUntrustedCertificates(true);
ffProfile.setAssumeUntrustedCertificateIssuer(false);
ffProfile.setPreference("extensions.shownSelectionUI", true);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability(FirefoxDriver.PROFILE, ffProfile);
driver = new FirefoxDriver(ffProfile);
driver.get("https://my_url/");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.close();
System.exit(0);
}}
我看到浏览器已启动,对话框显示如附件中所示。
我以为我的代码是:
ffProfile.setAcceptUntrustedCertificates(true);
会确保对话框会被处理(例如"按ok")?
我怎么能告诉浏览器"总是接受" Firefox配置文件中的证书?