上章练习题答案
1.Selenium概述
▼ Selenium也不是简单一个工具,而是由几个工具组成,每个工具都有其特点和应用场景
Selenium1.0原理
2.Selenium2介绍
▼ Selenium2原理简介
Selenium2优势
Selenium2原理图
3.学习路线
▼ 学习步骤
学习资源
4.启动有配置项的浏览器
▼ Driver
代码
//默认安装路径启动
System.setProperty("webdriver.firefox.bin", "C:/Program Files (x86)/Mozilla Firefox/firefox.exe");
//启动不在默认安装路径的firefox
FirefoxDriver firefoxdriver = new FirefoxDriver(); firefoxdriver.get("http://www.baidu.com");
//启动指定exe的firefox
FirefoxBinary binary = new FirefoxBinary(new File("C:/Program Files (x86)/Mozilla Firefox/firefox.exe"));
FirefoxDriver driver = new FirefoxDriver(binary, null);
//动态加载firebug
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(new File("D:/firebug-2.0.17.xpi"));
profile.setPreference("extensions.firebug.currentVersion", "2.0.17");
profile.setEnableNativeEvents(true); //启用firefox被禁用功能
profile.setPreference("extensions.firebug.allPagesActivation", "on");
//启动 自动开启firebug(设置插件属性)
FirefoxDriver driver = new FirefoxDriver(profile);
//设置浏览器属性
String proxyIp = "10.17.171.11";
int proxyPort = 8080;
FirefoxProfile profile = new FirefoxProfile();
//设置代理参数
profile.setPreference("network.proxy.type", 1);
profile.setPreference("network.proxy.http", proxyIp);
profile.setPreference("network.proxy.http_port", proxyPort);
//设置默认下载路径
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.dir", "D:\\");
FirefoxDriver driver = new FirefoxDriver(profile);
//设置主页地址
profile.setPreference("browser.startup.homepage", "http://www.huicewang.com");
FirefoxDriver driver = new FirefoxDriver(profile);
//启动指定用户配置文件的firefox
FirefoxProfile profile = new FirefoxProfile(new File("D:\\"));
profile.addExtension(new File("source/firebug-2.0.17.xpi"));
profile.addExtension(new File("D:/netExport-0.8.xpi"));
profile.setPreference("extensions.firebug.currentVersion", "2.0.17");
profile.setPreference("extensions.firebug.allPagesActivation", "on");
profile.setPreference("extensions.firebug.defaultPanelName", "net");
profile.setPreference("extensions.firebug.net.enableSites", true);
profile.setPreference("extensions.firebug.netexport.alwaysEnableAutoExport", true);
profile.setPreference("extensions.firebug.netexport.saveFiles", true);
profile.setPreference("extensions.firebug.netexport.defaultLogDir", "d:\\");
FirefoxDriver driver = new FirefoxDriver(profile);
Thread.sleep(2000);
driver.get("http://www.baidu.com");
driver.get("http://www.huicewang.com");
//通过配置文件名称启动指定firefox
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile profile = allProfiles.getProfile("default");
FirefoxDriver driver = new FirefoxDriver(profile);