使用默认方式构建的(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. html中一些常用标签及属性

    html中标签分为块级标签和行级标签 块级标签常用的有 <div> <p> <h1><hr><pre><table><ul ...

  2. 摘记—Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Cha

    What a Unicode string ? The binaries in RAM have the final word. NOT string literals in Text Editor( ...

  3. php 读取功能分割大文件实例详解

    在php中,对于文件的读取时,最快捷的方式莫过于使用一些诸如file.file_get_contents之类的函数.但当所操作的文件是一个比较大的文件时,这些函数可能就显的力不从心, 下面将从一个需求 ...

  4. paip.索引的种类以及实现attilax 总结

    paip.索引的种类以及实现attilax 总结 1. 索引的类型 1 2. Btree索引(分块索引) 1 3. Hash 索引(编号索引) 1 4. 倒排索引 2 5. 对大型文本文件做索引 2 ...

  5. 【Android】4.4 示例--列出手机上的所有联系人

    分类:C#.Android.VS2015:创建日期:2016-02-06 项目名:DesignerWalkthrough 模板:Blank App(Android) 功能:列出手机上的所有联系人. 说 ...

  6. POJ 2553 The Bottom of Graph 强连通图题解

    Description We will use the following (standard) definitions from graph theory. Let V be a nonempty ...

  7. IT人都非常忙(茫)

    我发现.身边的盆友都非常忙,要么在加班.要么加班刚回家:要么在出差,要么刚出差回来. 难道搞IT的人都非常忙么?忙还是茫? 大学期间.不知道未来要干什么.非常多人也不清楚应该学习哪些知识和技能.是否须 ...

  8. android Handlerr.removeCallbacksAndMessages(null)的妙用

    今天在阅读代码发现了android  Handlerr.removeCallbacksAndMessages(null)代码 在ondestory()调用,之前没用过,那想弄懂咋办,查api: pub ...

  9. 使用OleDB组件连接和访问Oracle数据库

    访问 Oracle 数据库的步骤 .在 Oracle 中,创建一个名为 TestTable 的表,如下所示: Create Table TestTable (c1 )); .将数据插入到 TestTa ...

  10. vue自动化单元测试

    // 引用vue和需要测试的组件 import Vue from 'vue' import HelloWorld from '@/components/HelloWorld' // 创建测试套件,一个 ...