浏览器禁用更新:

  因为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() 刷新

最新文章

  1. PHP 真正多线程的使用
  2. JSONP详解
  3. JSP之WEB服务器:Apache与Tomcat的区别 ,几种常见的web/应用服务器
  4. apache 局域网访问
  5. Redis ConnectionException
  6. EXT.net DateField format设置
  7. DIY一个前端模板引擎.(一)
  8. DEDECMS数据库执行原理、CMS代码层SQL注入防御思路
  9. ContentProvider官方教程(6)provider支持的数据类型
  10. OO真经——关于面向对象的哲学体系及科学体系的探讨(下)
  11. create-react-app创建的项目中registerServiceWorker.js文件的作用
  12. java(一) 基础部分
  13. HAOI2018 简要题解
  14. spring boot -thymeleaf-遍历list和map
  15. Java serialVersionUID作用和生成
  16. Dubbo学习笔记11:使用Dubbo中需要注意的一些事情
  17. component和bean区别
  18. ACM1005:Number Sequence
  19. Java Input Stream Diagram
  20. java代码====实现按钮点击改变颜色=======

热门文章

  1. python学习之控制语句
  2. Supervisor进程监控
  3. cocos2d-x android8.0 视频层遮挡问题
  4. NIO:异步非阻塞I/O,AIO,BIO
  5. fn project 生产环境使用
  6. Java各种集合容器的总结
  7. idea的有些路径问题
  8. mysql时间运算
  9. Win7旗舰版一直显示检查更新的问题
  10. 简述FPGA的一些优势