浏览器禁用更新:

  因为selenium对浏览器的支持是有限制的。当浏览器更新到最新版本时,需要下载支持最新版本的插件。有时候selenium还没有更新到支持最新版本的插件,但本地已经更新到最新版本了。这样就比较悲剧了。需要卸载掉浏览器重新安装旧版本。如果及时设置不自动更新。可以很好的解决这个问题。

  禁用chrome浏览器: 控制面板\系统和安全\管理工具\服务\chrome更新服务 禁用
  禁用Firefox浏览器:选项、高级、更新、不检查更新。F10 关于。。。查看版本
  禁用IE浏览器:https://zhidao.baidu.com/question/564473961.html

1、加载chrome浏览器:

package myseleniumtest;
import java.io.File;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions; public class chromeTest extends testBase { public static void main(String[] args) {
// TODO Auto-generated method stub
open_chrome();
}
static {
System.setProperty("webdriver.chrome.driver", "files/chromedriver.exe");
} public static void open_chrome() {
ChromeOptions options = new ChromeOptions();
// options.addArguments("--test-type");
// File file =new File("files/chrome/User Data");
// options.addArguments("user-data-dir="+file.getAbsolutePath());
options.addArguments("--test-type", "--start-maximized");
WebDriver driver = new ChromeDriver(options);
driver.get(strUrl);
} // 加载crx插件
public static void load_plug() {
ChromeOptions op = new ChromeOptions();
op.addExtensions(new File(""));
driver = new ChromeDriver(op);
}
// 根据配置文件夹启动 User Data文件夹在 C:\Users\Administrator\AppData\Local\Google\Chrome\User Data 路径下
public static void loadConfig() {
ChromeOptions options = new ChromeOptions();
File file = new File("files/chrome/User Data");
options.addArguments("user-data-dir=" + file.getAbsolutePath());
options.addArguments("--test-type", "--start-maximized");
WebDriver driver = new ChromeDriver(options);
driver.get(strUrl);
} }

2、加载 firefox浏览器:

package myseleniumtest;

import java.io.File;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.remote.DesiredCapabilities; public class firefoxTest extends testBase { public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver", "files/geckodriver.exe");
// load_firebug();
load_firebug();
}
//OpenDefault
public static void open_firefox(){ WebDriver driver = new FirefoxDriver();
driver.get(strUrl);
}
//加载插件 about:config
public static void load_firebug(){
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(new File("files/firefox/firebug@software.joehewitt.com.xpi"));
profile.setPreference("extensions.firebug.currentVersion", "2.0.19");
FirefoxOptions options = new FirefoxOptions();
options.setProfile(profile);
driver = new FirefoxDriver(options); }
public static void exportFile(){
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.dir","c:\\");
// 0桌面 1我的下载 2自定义
profile.setPreference("browser.download.folderList",2);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk","browser.helperApps.neverAsk.saveToDisk");
driver = new FirefoxDriver(new FirefoxOptions().setProfile(profile));
driver.get("http://wiki.yslocal.com/pages/viewpage.action?pageId=6719652");
}
//启用功能 在浏览器地址栏输入 about:config
public static void startExtend(){
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("", true);
}
// 启动本机的firefox配置
public static void loadLocalConfig(){
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile profile = allProfiles.getProfile("default");
profile.setPreference("extensions.firebug.allPagesActivation", "on");
driver = new FirefoxDriver(new FirefoxOptions().setProfile(profile));
}
//启用其他机器的配置文件
//将A机器上的profiles文件夹拷出来 C:\Users\Administrator\AppData\Local\Mozilla\Firefox
public static void loadOtherConfig(){
File f = new File("files/firefox/Profiles/gsz6831l.default/");
FirefoxProfile profile = new FirefoxProfile(f);
driver = new FirefoxDriver(new FirefoxOptions().setProfile(profile)); } }

3、加载IE浏览器

package myseleniumtest;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities; public class ieTest extends testBase { public static void main(String[] args) {
// TODO Auto-generated method stub }
//关闭保护模式 安全的四个选项 unchecked
public void uncheckedSettings(){
DesiredCapabilities d =DesiredCapabilities.internetExplorer();
d.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
d.setCapability("ignoreProtectedModeSettings",true);
}
public static void open_ie(){
System.setProperty("webdriver.ie.driver","files/IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get(strUrl);
} }
driver.navigate().back() 后退
driver.navigate().forward() 前进
driver.navigate().refresh() 刷新

selenium3加载浏览器的更多相关文章

  1. Qt加载网页(加载浏览器插件)和制作托盘后台运行(南信大财务报账看号)

    程序模块要添加QNetWork和QWebKit模块: nuistfinancevideo.h文件: #ifndef NUISTFINANCEVIDEO_H #define NUISTFINANCEVI ...

  2. No.11 selenium学习之路之加载浏览器插件for Firefox

    打开帮助 —— 故障排除信息

  3. selenium自动化之加载浏览器的配置文件

    做seleniumUI自动化关于选用哪个浏览器方面,对于我来说,火狐浏览器只是用于定位元素,因为有firebug(注意高版本的火狐已经安装不了这个插件了),而真正执行自动化脚本用的是谷歌,感觉谷歌的速 ...

  4. Blazor-断开连接后重新加载浏览器

    在大多数情况下,Blazor将与以前相同的线路上重新连接到服务器.但有时无法重新连接,需要重新加载web浏览器才能使网站重新工作.如果服务器回收应用程序池,则需要手动重新加载页面在没有调试的情况下在I ...

  5. selenium自动化之加载浏览器配置文件

    化环境:python3.6 + selenium3 当我们做自动化的时候,如果不做任何配置的话打开的浏览器默认是不加载我们的浏览器配置文件的,下面我们来说说如何加载配置文件: 首先不管使用的是火狐浏览 ...

  6. 从url到页面加载浏览器做了什么?

    从输入url到页面加载发生了什么?1.DNS解析DNS解析是一个递归查询的过程.DNS解析的过程就是寻找哪台机器上有你需要资源的过程,当你在浏览器中输入一个地址时,www.baidu.com.其实不是 ...

  7. vue懒加载 && 浏览器高度

    当我们进入首页时,可能有很多条目需要显示,但是如果条目太多,我们全部将之显示出来就会造成性能的消耗,比如,我在第一条就找到了需要的或者我就看前面两条我就不想看后面的了,所以,这时候如果使用全部加载的方 ...

  8. 用selenium自动加载浏览器下载图片

    上一篇用requests这个库进行图片的批量下载,只所以可以这样做,是因为豆瓣提供的XHR的接口API,而且接口返回的数据类型为json格式,所以使用起来非常的方便,但是有时候我们需要分析html格式 ...

  9. selenium模块跳过用户名密码验证码输入,加载浏览器标签和cookie,进行翻页爬虫多页动态加载的数据(js)

    能解决登陆一次后,之后不需要二次登陆的动态加载数据,网页保存的cookie和标签,加入到selenium自动化测试浏览器中 1 from selenium import webdriver 2 imp ...

随机推荐

  1. opencv 识别答题卡

    参考这个网站,然后自己 找了张图片试了一下 http://blog.csdn.net/cp562090732/article/details/47804003 // test.cpp : 定义控制台应 ...

  2. RIP 知识要点

    RIP知识要点: UDP:520 版本:v1(广播包更新) / v2(组播更新 224.0.0.9  ) 度量值:跳数(最多跳15跳,路由为16跳时路由不可达) =================== ...

  3. Weex入门篇——Mac 安装Weex

    相关文档:http://blog.csdn.net/jasonblog/article/details/51863173 前言 相比较于React Native的“Learn once, write ...

  4. Robot Framework接口测试(1)

    RF是做接口测试的一个非常方便的工具,我们只需要写好发送报文的脚本,就可以灵活的对接口进行测试. 做接口测试我们需要做如下工作: 1.拼接发送的报文 2.发送请求的方法 3.对结果进行判断 我们先按步 ...

  5. 剑指offer-第四章解决面试题思路(二叉收索树和双向链表)

    题目:输入一个二叉收索树,将二叉搜索树转换成排序的双向链表.要求不能创建节点,只能将链表中的指针进行改变. 将复杂的问题简单化:思路:二叉收索树,本身是一个排序结构,中序遍历二叉收索树就可以得到一组排 ...

  6. 十五、python沉淀之路--eval()的用法

    一.eval函数 python eval() 函数的功能:将字符串str当成有效的表达式来求值并返回计算结果. 语法:eval(source[, globals[, locals]]) -> v ...

  7. gulp 流处理

    包含的内容:     穿插流     流合并     流队列     流筛选 1. 穿插流 // passthrough stream 把流传递给其他的 // use gulp.src(glob,{p ...

  8. gitlab Failed to register this runner. Perhaps you are having network problems runner 注册失败问题解决

    1. 低版本安装地址 https://gitlab-ci-multi-runner-downloads.s3.amazonaws.com/v1.11.2/index.html   2. 使用 yum ...

  9. vue的双向绑定原理解析(vue项目重构二)

    现在的前端框架 如果没有个数据的双向/单向绑定,都不好意思说是一个新的框架,至于为什么需要这个功能,从jq或者原生js开始做项目的前端工作者,应该是深有体会. 以下也是个人对vue的双向绑定原理的一些 ...

  10. hive外表parquet文件

    外表关联parquet文件 1. 为什么关联了一次数据文件就不能二次被使用: 2. 为什么删除了employee,select还是可以而且有数据,1,2可能是一个问题   外表drop只是metada ...