使用默认方式构建的(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. PSAPI和ToolHelpAPI学习笔记

    标 题: PSAPI学习笔记 作 者:北极星2003 时 间:2005-07-24 18:36 链 接:http://bbs.pediy.com/showthread.php?threadid=154 ...

  2. Latex算法伪代码使用总结

    Latex伪代码使用总结 algorithmicx例子 相应代码: \documentclass[11pt]{ctexart} \usepackage[top=2cm, bottom=2cm, lef ...

  3. Hadoop2.x介绍与源代码编译

    1.Hadoop 项目的四大模块 Hadoop Common: The common utilities that support the other Hadoop modules. Hadoop D ...

  4. Correlation and Regression

    Correlation and Regression Sample Covariance The covariance between two random variables is a statis ...

  5. [sh]uniq-sort-awk

    题目:[百度搜狐面试题] 统计url出现次数 oldboy.log http://www.etiantain.org/index.html http://www.etiantain.org/1.htm ...

  6. [na]wireshark抓包排错-tcp.flags.reset

    这是以前处理无线portal问题时候的一个梗. 一 抓包思路-用抓包来解决问题 ,了解协议交互大概过程 ,抓包 抓包法则: .最小化原则,过滤到想要的最小数据,别忽略上下文数据包 .对比法, 正常的包 ...

  7. 在java代码中用xslt处理xml文件

    java处理xml文件 import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundExceptio ...

  8. C语言可变参数宏及‘##’在可变参数中的作用

    测试代码及解释: #include <stdio.h> #define PRINT(x) printf x #define SECONDPRINT(fmt,arg...) printf(f ...

  9. Linux命令(24) :sort

    转载地址:点击 linux 命令详解 sort是在Linux里非常常用的一个命令,管排序的,集中精力,五分钟搞定sort,现在开始! 1 sort的工作原理 sort将文件的每一行作为一个单位,相互比 ...

  10. How-to: Tune Your Apache Spark Jobs (Part 1)

    Learn techniques for tuning your Apache Spark jobs for optimal efficiency. When you write Apache Spa ...