浏览器禁用更新:

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

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

1、加载chrome浏览器:

  1. package myseleniumtest;
  2. import java.io.File;
  3. import org.openqa.selenium.WebDriver;
  4. import org.openqa.selenium.chrome.ChromeDriver;
  5. import org.openqa.selenium.chrome.ChromeOptions;
  6.  
  7. public class chromeTest extends testBase {
  8.  
  9. public static void main(String[] args) {
  10. // TODO Auto-generated method stub
  11. open_chrome();
  12. }
  13. static {
  14. System.setProperty("webdriver.chrome.driver", "files/chromedriver.exe");
  15. }
  16.  
  17. public static void open_chrome() {
  18. ChromeOptions options = new ChromeOptions();
  19. // options.addArguments("--test-type");
  20. // File file =new File("files/chrome/User Data");
  21. // options.addArguments("user-data-dir="+file.getAbsolutePath());
  22. options.addArguments("--test-type", "--start-maximized");
  23. WebDriver driver = new ChromeDriver(options);
  24. driver.get(strUrl);
  25. }
  26.  
  27. // 加载crx插件
  28. public static void load_plug() {
  29. ChromeOptions op = new ChromeOptions();
  30. op.addExtensions(new File(""));
  31. driver = new ChromeDriver(op);
  32. }
  33. // 根据配置文件夹启动 User Data文件夹在 C:\Users\Administrator\AppData\Local\Google\Chrome\User Data 路径下
  34. public static void loadConfig() {
  35. ChromeOptions options = new ChromeOptions();
  36. File file = new File("files/chrome/User Data");
  37. options.addArguments("user-data-dir=" + file.getAbsolutePath());
  38. options.addArguments("--test-type", "--start-maximized");
  39. WebDriver driver = new ChromeDriver(options);
  40. driver.get(strUrl);
  41. }
  42.  
  43. }

2、加载 firefox浏览器:

  1. package myseleniumtest;
  2.  
  3. import java.io.File;
  4.  
  5. import org.openqa.selenium.WebDriver;
  6. import org.openqa.selenium.firefox.FirefoxDriver;
  7. import org.openqa.selenium.firefox.FirefoxOptions;
  8. import org.openqa.selenium.firefox.FirefoxProfile;
  9. import org.openqa.selenium.firefox.internal.ProfilesIni;
  10. import org.openqa.selenium.remote.DesiredCapabilities;
  11.  
  12. public class firefoxTest extends testBase {
  13.  
  14. public static void main(String[] args) {
  15. // TODO Auto-generated method stub
  16. System.setProperty("webdriver.gecko.driver", "files/geckodriver.exe");
  17. // load_firebug();
  18. load_firebug();
  19. }
  20. //OpenDefault
  21. public static void open_firefox(){
  22.  
  23. WebDriver driver = new FirefoxDriver();
  24. driver.get(strUrl);
  25. }
  26. //加载插件 about:config
  27. public static void load_firebug(){
  28. FirefoxProfile profile = new FirefoxProfile();
  29. profile.addExtension(new File("files/firefox/firebug@software.joehewitt.com.xpi"));
  30. profile.setPreference("extensions.firebug.currentVersion", "2.0.19");
  31. FirefoxOptions options = new FirefoxOptions();
  32. options.setProfile(profile);
  33. driver = new FirefoxDriver(options);
  34.  
  35. }
  36. public static void exportFile(){
  37. FirefoxProfile profile = new FirefoxProfile();
  38. profile.setPreference("browser.download.dir","c:\\");
  39. // 0桌面 1我的下载 2自定义
  40. profile.setPreference("browser.download.folderList",2);
  41. profile.setPreference("browser.helperApps.neverAsk.saveToDisk","browser.helperApps.neverAsk.saveToDisk");
  42. driver = new FirefoxDriver(new FirefoxOptions().setProfile(profile));
  43. driver.get("http://wiki.yslocal.com/pages/viewpage.action?pageId=6719652");
  44. }
  45. //启用功能 在浏览器地址栏输入 about:config
  46. public static void startExtend(){
  47. FirefoxProfile profile = new FirefoxProfile();
  48. profile.setPreference("", true);
  49. }
  50. // 启动本机的firefox配置
  51. public static void loadLocalConfig(){
  52. ProfilesIni allProfiles = new ProfilesIni();
  53. FirefoxProfile profile = allProfiles.getProfile("default");
  54. profile.setPreference("extensions.firebug.allPagesActivation", "on");
  55. driver = new FirefoxDriver(new FirefoxOptions().setProfile(profile));
  56. }
  57. //启用其他机器的配置文件
  58. //将A机器上的profiles文件夹拷出来 C:\Users\Administrator\AppData\Local\Mozilla\Firefox
  59. public static void loadOtherConfig(){
  60. File f = new File("files/firefox/Profiles/gsz6831l.default/");
  61. FirefoxProfile profile = new FirefoxProfile(f);
  62. driver = new FirefoxDriver(new FirefoxOptions().setProfile(profile));
  63.  
  64. }
  65.  
  66. }

3、加载IE浏览器

  1. package myseleniumtest;
  2.  
  3. import org.openqa.selenium.WebDriver;
  4. import org.openqa.selenium.ie.InternetExplorerDriver;
  5. import org.openqa.selenium.remote.DesiredCapabilities;
  6.  
  7. public class ieTest extends testBase {
  8.  
  9. public static void main(String[] args) {
  10. // TODO Auto-generated method stub
  11.  
  12. }
  13. //关闭保护模式 安全的四个选项 unchecked
  14. public void uncheckedSettings(){
  15. DesiredCapabilities d =DesiredCapabilities.internetExplorer();
  16. d.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
  17. d.setCapability("ignoreProtectedModeSettings",true);
  18. }
  19. public static void open_ie(){
  20. System.setProperty("webdriver.ie.driver","files/IEDriverServer.exe");
  21. WebDriver driver = new InternetExplorerDriver();
  22. driver.get(strUrl);
  23. }
  24.  
  25. }
  1. driver.navigate().back() 后退
  2. driver.navigate().forward() 前进
  3. 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. Kali Linux安装SSH Server

    Kali Linux默认并没有安装SSH服务,为了实现远程登录Kali Linux,我们需要安装SSH服务. 安装 OpenSSH Server # apt-get install openssh-s ...

  2. 迁移 Windows 上 Oracle 11.2.0.3.0 到 Linux 上 Oracle 11.2.0.3.0

    一.迁移前数据库基本信息统计 查看数据库版本 SELECT * FROM V$VERSION; /* Oracle Database 11g Enterprise Edition Release 11 ...

  3. Python学习-数据运算

    在Python中有丰富的算术运算,这使得Python在科学计算领域有着很高的地位,Python可以提供包括四则运算在内的各种算术运算. a = 10 b = 20 print(a-b) #-10 pr ...

  4. 解决spring 事务管理默认不支持SQLException等运行时异常

    公司同事在定位一个bug时,发现spring默认的事务只支持运行时异常的回滚,对于像SQLException这样的非运行时异常,默认的事务机制不能处理,于是找了下解决的办法:    1.在捕获SQLE ...

  5. composer 详解

    composer 详解 http://blog.csdn.net/panpan639944806/article/details/16808261 https://www.phpcomposer.co ...

  6. Does Windows have a limit of 2000 threads per process?

    http://blogs.msdn.com/b/oldnewthing/archive/2005/07/29/444912.aspx Often I see people asking why the ...

  7. oracle里的查询转换

    oracle里的查询转换的作用 Oracle里的查询转换,有称为查询改写,指oracle在执行目标sql时可能会做等价改写,目的是为了更高效的执行目标sql 在10g及其以后的版本中,oracle会对 ...

  8. 24 mysql怎么保证主备一致

    Mysql主备的基本原理 在状态1中,客户端直接访问节点A,而节点B只是备库,只是将A的binlog全部同步过来并应用到本地,这样可以保持节点B和节点A的数据是相同的. 当需要切换的时候,就变成状态2 ...

  9. 关于 object-c的@protocol的理解

    从java角度来理解 @protocol 相当于 java 的接口定义,用法也一样 下面是试验例子 @protocol mytestClass <NSObject> - (void) ca ...

  10. Python Twisted网络编程框架与异步编程入门教程

    原作出处:twisted-intro-cn 作者:Dave 译者:杨晓伟 luocheng likebeta 转载声明:版权归原作出处所有,转载只为让更多人看到这部优秀作品合集,如果侵权,请留言告知 ...