1、启动Chrome "webdriver.chrome.driver"

System.setProperty("webdriver.chrome.driver", "files\\chromedriver.exe");  //指定驱动路径

WebDriver driver = new ChromeDriver();

加载插件及使用用户默认浏览器配置

System.setProperty("webdriver.chrome.driver", "files\\chromedriver.exe");

File file = new File ("files\\youtube.crx");//获取插件

ChromeOptions options = new ChromeOptions();

options.addExtensions(file);//加载插件

options.addArguments("user-data-dir=C:/Users/test/AppData/Local/Google/Chrome/User Data");//制定配置文件地址

WebDriver driver = new ChromeDriver(options);

2、启动Firefox  "webdriver.firefox.bin"

System.setProperty("webdriver.firefox.bin","D:/Program Files/Mozilla Firefox/firefox.exe");  

WebDriver driver = new FirefoxDriver();

启动浏览器时加载插件

System.setProperty("webdriver.firefox.bin", "D:/Program Files/Mozilla Firefox/firefox.exe");

File file = new File("files/firebug-2.0.7-fx.xpi");

FirefoxProfile profile = new FirefoxProfile();

try {

  profile.addExtension(file);

} catch (IOException e) {

  e.printStackTrace();

}
profile.setPreference("extensions.firebug.currentVersion", "2.0.7");
//active firebug extensions
profile.setPreference("extensions.firebug.allPagesActivation", "on");   
WebDriver driver = new FirefoxDriver(profile);

启动firefox时设置profile:
String proxyIp = "10.17.171.11";
int proxyPort = 8080;
System.out.println("start firefox browser...");
System.setProperty("webdriver.firefox.bin",
        "D:/Program Files/Mozilla Firefox/firefox.exe");
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:\\");
WebDriver driver = new FirefoxDriver(profile);

启动本机器的firefox配置

System.setProperty("webdriver.firefox.bin",

"D:/Program Files/Mozilla Firefox/firefox.exe");

ProfilesIni pi = new ProfilesIni();

FirefoxProfile profile = pi.getProfile("default");

WebDriver driver = new FirefoxDriver(profile);

查看更多配置项可打开firefox,输入about:config。

3、启动IE  "webdriver.ie.driver"

System.setProperty("webdriver.ie.driver", "files\\IEDriverServer.exe");

WebDriver driver = new InternetExplorerDriver();

关闭IE保护模式

System.setProperty("webdriver.ie.driver", "files\\IEDriverServer.exe");

DesiredCapabilities dc = DesiredCapabilities.internetExplorer();

dc.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);

//IE默认启动保护模式,要么手动在浏览器的设置中关闭保护模式,要么在代码中加上这一句,即可

dc.setCapability("ignoreProtectedModeSettings", true);

WebDriver driver = new InternetExplorerDriver(dc);

未完待续。。。。。。。。

Selenium启动不同浏览器的更多相关文章

  1. selenium 启动ie 浏览器

    selenium 启动ie 浏览器 var driver = new InternetExplorerDriver(@"IEDriverServer.exe路径"); driver ...

  2. Selenium 启动无头浏览器,只有chrome 和 firefox的,没有IE

    使用无头浏览器,可以避免掉不确定的弹出框对脚本稳定性的影响,还能在脚本执行过程中省略掉了css 加载的时间. 以下是Selenium 启动无头浏览器的方法,只有chrome 和 firefox的. p ...

  3. 7.解决在python中用selenium启动FireFox浏览器启动不了的方法

    首次在利用python中的selenium启动FireFox浏览器时可能碰到如下问题 当输入如下代码时: from selenium import webdriver brower=webdriver ...

  4. 解决selenium 启动ie浏览器报错:Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones

    启动ie代码: System.setProperty("webdriver.ie.driver", "bin/IEDriverServer.exe"); Web ...

  5. Selenium启动Chrome浏览器提示“请停用以开发者模式运行的扩展程序”的解决办法

    安装了python selenium,运行下面代码: 1 from selenium import webdriver 2 3 browser = webdriver.Chrome() 4 brows ...

  6. 使用selenium启动火狐浏览器,解决Unable to create new remote session问题

    今天用火狐浏览器来做自动化,才启动就报错,提示不能创建新的session,不能启动浏览器 问题原因: 火狐driver与火狐浏览器与selenium版本的不兼容 我使用的火狐driver是0.21.0 ...

  7. 用selenium启动chrome浏览器

    python 3.7 pycharm 1.安装selenium pip3 install selenium 2.下载与chrome匹配的chromdriver.exe,放到项目的解释器路径下,跟pyt ...

  8. java selenium启动火狐浏览器报错:Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: VISTA Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:14.666Z

    Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: VISTA Build in ...

  9. selenium+python自动化100-centos上搭建selenium启动chrome浏览器headless无界面模式

    环境准备 前言 selenium在windows机器上运行,每次会启动界面,运行很不稳定.于是想到用chrome来了的headless无界面模式,确实方便了不少. 为了提高自动化运行的效率和稳定性,于 ...

随机推荐

  1. 一个关于C++拷贝构造的bug

    #include <iostream> using namespace std; class A { public: A(int a) {}; A(const A&) = defa ...

  2. Vtk读取并显示保存图像

    (1):Vtk读取并显示图像:三种方法 转载:未知出处 转载:用VTK显示平面图片:http://blog.csdn.net/tonylk/article/details/464881 用到vtkJP ...

  3. 0xc000007b:vs2012+Opencv2.4.4出现"0xc000007b"问题

    在64位系统中,VS2012+opencv2.4.4下编程出现一个问题,我简单的读取图片就出现"应用程序无法正常启动0xc000007b"的问题:如图: 注意事项:把运行环境改成  ...

  4. 网页小技巧-360doc个人图书馆复制文字

    用过这个网站的人知道,当你像平时一样复制网页的地址时,这个网站会弹出如下的提示框: 这时候如果你没有账号,又不想注册.真的是一种很崩溃的感觉,但是除了注册登录外,就没有其他的办法了吗? 熟悉网页调试的 ...

  5. BZOJ 5508: [Tjoi2019]甲苯先生的字符串 矩阵乘法_思维

    求 $f[i][j]=∑f[i−1][k]$,$'a'<=k<='z'$ . 用矩阵乘法转移一波即可. 竟然独自想出来了QAQ Code: #include <bits/stdc++ ...

  6. IDEA 社区版 点击‘Edit Configurations’打开“Run/Debug Configurations”,里面没有tomcat server选项

    没错 社区版就是没有 “先手动添加Plugins 然后再setting” 方法无效 搜索不到 http://blog.csdn.net/u010666884/article/details/52119 ...

  7. select Option(增加,删除,清空)

    jQuery获取Select选择的Text和Value: $("#select_id").change(function(){//code...}); //为Select添加事件, ...

  8. 移植Mplayer到OK6410开发板

    移植Mplayer到OK6410开发板 作者:vasage 项目需要,需要将Mplayer移植到开发板上,所以今天花了一下下午成功移植,其中参考很多文档,后发现许多文档陈旧,些许文档有少量错误,所以这 ...

  9. @value 注解获取属性文件中的值

    一.属性文件 db.properties name=jack 二.配置文件 applicationContext.xml <!-- 加载配置文件,该节点只能存在一个,所以用 * ,加载所有属性文 ...

  10. SQLPlus在连接时通常有四种方式

    SQLPlus在连接时通常有四种方式 1. ? 1 sqlplus / as sysdba 操作系统认证,不需要数据库服务器启动listener,也不需要数据库服务器处于可用状态.比如我们想要启动数据 ...