FirefoxProfile定制启动firefox
1 package seleniumtraining1;
2
3 import java.io.File;
4 import java.io.IOException;
5
6 import org.openqa.selenium.By;
7 import org.openqa.selenium.WebDriver;
8 import org.openqa.selenium.WebElement;
9 import org.openqa.selenium.firefox.FirefoxDriver;
10 import org.openqa.selenium.firefox.FirefoxProfile;
11 import org.openqa.selenium.support.ui.ExpectedConditions;
12 import org.openqa.selenium.support.ui.WebDriverWait;
13
14 public class seleniumtest1 {
15
16 public static void main(String[] args) {
17 String profileInJson = "";
18 FirefoxProfile profile = new FirefoxProfile();
19 try{
20 profile.addExtension(new File("/path/to/extension.xpi"));
21 profile.setPreference("browser.startup.homepage", "about.blank");
22 profile.setAssumeUntrustedCertificateIssuer(false);
23 profile.setAcceptUntrustedCertificates(false);
24
25 profileInJson = profile.toJson();
26 System.out.println(profileInJson);
27 }catch(IOException e){
28 e.printStackTrace();
29 }
30 System.setProperty("webdriver.firefox.bin","D:/Program Files/Mozilla firefox4002/firefox.exe");
31 WebDriver driver = new FirefoxDriver();
32 driver.get("http://www.daidu.com");
33 String url = driver.getCurrentUrl();
34 System.out.println(url);
35 driver.close();
36 }
37
38 }