使用默认方式构建的(WebDriver)FirefoxDriver实例:

WebDriver driver = new FirefoxDriver();

这种方式下,打开的Firefox浏览器将是不带任何插件的浏览器,和初始安装一样的状态。有时在测试中需要使用到预先保留的一些信息,比如Cookie中的用户名和密码等,显然这种方式不适用了。

这里可以采用下面的方式来构建(WebDriver)FirefoxDriver实例:

String firefoxProfileDir = "C:\\Users\\XXXXX\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\a6xwo0b1.default";

FirefoxProfile profile = new FirefoxProfile(new File(firefoxProfileDir));

WebDriver driver = new FirefoxDriver(profile);

这里firefoxProfileDir的获取方式是:

通过在开始菜单中的“搜索程序和文件”中输入%APPDATA%\Mozilla\Firefox\Profiles\ 来获取路径

详细可以参考

http://www.tuicool.com/articles/NJv6Nj

https://support.mozilla.org/zh-CN/kb/用户配置文件

实例:

package com.test.mouse;

import java.io.File;
import java.util.Iterator;
import java.util.Set; import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile; public class MouseOperation { public static void main(String[] args) { //通过加载配置文件使得由WebDriver启动的firefox浏览器也能共享之前安装过的插件以及保存的密码等信息
FirefoxProfile profile = new FirefoxProfile(new File("C:\\Users\\huangch\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\a6xwo0b1.default"));
WebDriver driver = new FirefoxDriver(profile); driver.get("http://c37.yunpan.360.cn");
driver.manage().window().maximize();
waitTime(5000); driver.findElement(By.xpath("//*[@id='infoPanel']/a[2]")).click(); //可以使用下面的方法将当前页面对应的Cookies内容打印出来
Set<Cookie> setCookie = driver.manage().getCookies();
Iterator iterator = setCookie.iterator();
while(iterator.hasNext()){
Cookie c = (Cookie) iterator.next();
System.out.println(c.getDomain()+"---"+c.getName()+"---"+c.getPath()+"---"+c.getValue());
} } static public void waitTime(int time) { try {
Thread.sleep(time);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} }

获取FirefoxProfile配置文件以及使用方法介绍的更多相关文章

  1. Windows下获取本机IP地址方法介绍

    Windows下获取本机IP地址方法介绍 if((hostinfo = gethostbyname(name)) != NULL) { #if 1 ; printf("IP COUNT: % ...

  2. JS数组at函数(获取最后一个元素的方法)介绍

    本文介绍js中数组的at函数,属于比较简单的知识普及性文章,难度不大. 0x00 首先,我们可以思考如下一个问题,如果要获取一个数组的最后一个元素(这是很常用的操作),我们应该怎么做? 相信大部分人能 ...

  3. Java 获取*.properties配置文件中的内容 ,常见的两种方法

    import java.io.InputStream; import java.util.Enumeration; import java.util.List; import java.util.Pr ...

  4. 爬虫 Http请求,urllib2获取数据,第三方库requests获取数据,BeautifulSoup处理数据,使用Chrome浏览器开发者工具显示检查网页源代码,json模块的dumps,loads,dump,load方法介绍

    爬虫 Http请求,urllib2获取数据,第三方库requests获取数据,BeautifulSoup处理数据,使用Chrome浏览器开发者工具显示检查网页源代码,json模块的dumps,load ...

  5. SWIFT中获取配置文件路径的方法

    在项目中有时候要添加一些配置文件然后在程序中读取相应的配置信息,以下为本人整理的获取项目配置文件(.plist)路径的方法: 1.获取沙盒路径后再APPEND配置文件 func documentsDi ...

  6. Spring AOP基于配置文件的面向方法的切面

    Spring AOP基于配置文件的面向方法的切面 Spring AOP根据执行的时间点可以分为around.before和after几种方式. around为方法前后均执行 before为方法前执行 ...

  7. python动态获取对象的属性和方法 (转载)

    首先通过一个例子来看一下本文中可能用到的对象和相关概念. #coding:utf-8 import sys def foo():pass class Cat(object): def __init__ ...

  8. js获取鼠标位置的各种方法

    在一些DOM操作中我们经常会跟元素的位置打交道,鼠标交互式一个经常用到的方面,令人失望的是不同的浏览器下会有不同的结果甚至是有的浏览器下没结果,这篇文章就上鼠标点击位置坐标获取做一些简单的总结,没特殊 ...

  9. python动态获取对象的属性和方法

    http://blog.csdn.net/kenkywu/article/details/6822220首先通过一个例子来看一下本文中可能用到的对象和相关概念.01     #coding: UTF- ...

随机推荐

  1. ZOJ 1654 Place the Robots建图思维(分块思想)+二分匹配

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=654 AC一百道水题,不如AC一道难题来的舒服. 题意:一个n*m地图 ...

  2. 定时器quartz工具类

    一.gradle配置 // https://mvnrepository.com/artifact/org.quartz-scheduler/quartz compile group: 'org.qua ...

  3. unity, 让主角头顶朝向等于地面法线(character align to surface normal)

    计算过程如下: 1,通过由主角中心raycast一条竖直射线获得主角所在处地面法线,用作主角的newUp. 注:一定要从主角中心raycast,而不要从player.transform.positio ...

  4. dubbo-monitor监控台的部署

    参考资料:dubbo的monitorhttps://github.com/handuyishe/dubbo-monitorhttp://blog.yangcvo.me/2017/01/26/Java- ...

  5. Spring Boot 2.0官方文档之 Actuator(转)

    执行器(Actuator)的定义 执行器是一个制造业术语,指的是用于移动或控制东西的一个机械装置,一个很小的改变就能让执行器产生大量的运动. An actuator is a manufacturin ...

  6. Ambari-stack介绍

    Ambari-stack总体介绍 Ambari-stack 表示hadoop某个发行版本号.比如HDP-1.0.0,在用ambari创建一个集群时,首先要通过调用restfulAPI设置stack版本 ...

  7. linux快速进入全屏命令行模式

    按CTRL+ALT+F1~6就可以了.F7是桌面环境.

  8. 用javascript获得地址栏参数的两种方法

    javascript获得地址栏参数. 方法1: <script language="JavaScript"> //取地址栏参数 <!-- function Req ...

  9. 用Visual Studio Code写Node和调试代码

    介绍 vsc的宣传语是: 一个运行于 Mac OS X.Windows和 Linux 之上的,针对于编写现代 Web 和云应用的跨平台源代码编辑器. 按它说的,vsc特别适合来作为前端开发编辑器. 内 ...

  10. 利用命令行引用外部jar包以使程序正常执行的4种方法

    声明:本博客为原创博客.未经同意.不得转载!原文链接为http://blog.csdn.net/bettarwang/article/details/30976069 平时写一些小的Java Demo ...