其它

firefox代理

String PROXY = "localhost:8080";//如果不是本机,localhost替换成IP地址
org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(PROXY)
  .setFtpProxy(PROXY)
  .setSslProxy(PROXY);
DesiredCapabilities cap = new DesiredCapabailities();
cap.setPreference(CapabilityType.PROXY, proxy);
WebDriver driver = new FirefoxDriver(cap);

启用firefox禁用的功能

FirefoxProfile profile = new FirefoxProfile();
profile.setEnableNativeEvents(true);
WebDriver driver = new FirefoxDriver(profile);

临时指定插件

有时需要临时让启动的firefox带一个插件,如firebug,来定位问题等。首先要下载这个插件的xpi安装包。剩下的就让selenium webdriver来完成,如下:

FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
//避免启动画面
firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.10.1"); 
WebDriver driver = new FirefoxDriver(firefoxProfile);