[Selenium] 应对使用 Internet Explorer Driver 多个实例时的 cookie 共享问题
2015-06-03 15:07
519 查看
在使用 IEDriverServer 可执行文件时,从理论上来说是可通过它来创建并使用多个同时存在的 Internet Explorer Driver 实例的。但在实际使用过程中,总是会碰到与 cookie 相关的问题、窗口焦点的问题、浏览器多实例等可能会面临的问题。如果真想希望使用 Internet Explorer Driver 的多个实例并且尽可能的避免前述可能遇到的问题,建议考虑 RemoteWebDriver 的方式,并通过多台虚拟机来隔离干扰
有一种解决方案来应对使用 Internet Explorer Driver 多个实例时的 cookie 共享问题,即在Internet Explorer 启动时先清理回话中的脏数据。可通过将 IE_ENSURE_CLEAN_SESION 参数传递给 Internet Explorer Driver 并在此模式下启动 Internet Explorer Driver 来达到目的,代码如下
pachage com.learningselenium.simplewebdriver;
import org.openqa.selenium.*;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class testInternetExplorerDriver{
public static void main(String[] args){
System.setProperty("webdriver.ie.driver", "D:\Driver\IEDriverServer_ Win32_ 2.37.0_latest\IEDriverServer.exe");
//设置DesiredCapabilities 的属性包含IE_ENSURE_CLEAN_SESSION 以确保在浏览器实例启动之前清理会话的脏数据
DesiredCapabilities capab = DesiredCapabilities.internetExplorer();
capab.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
Webdriver driver = new InternetExplorerDriver(capab);
driver.get("http://www.baidu.com");
}
}
有一种解决方案来应对使用 Internet Explorer Driver 多个实例时的 cookie 共享问题,即在Internet Explorer 启动时先清理回话中的脏数据。可通过将 IE_ENSURE_CLEAN_SESION 参数传递给 Internet Explorer Driver 并在此模式下启动 Internet Explorer Driver 来达到目的,代码如下
pachage com.learningselenium.simplewebdriver;
import org.openqa.selenium.*;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class testInternetExplorerDriver{
public static void main(String[] args){
System.setProperty("webdriver.ie.driver", "D:\Driver\IEDriverServer_ Win32_ 2.37.0_latest\IEDriverServer.exe");
//设置DesiredCapabilities 的属性包含IE_ENSURE_CLEAN_SESSION 以确保在浏览器实例启动之前清理会话的脏数据
DesiredCapabilities capab = DesiredCapabilities.internetExplorer();
capab.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
Webdriver driver = new InternetExplorerDriver(capab);
driver.get("http://www.baidu.com");
}
}
相关文章推荐
- 遍历Map的四种方法
- USB OTG简介、与普通USB线的区别 分类: USB OTG驱动 生活百科 2015-06-03 15:07 352人阅读 评论(0) 收藏
- Oracle常用命令(no.3)
- 【新手上路】天气预报
- java发送http请求
- jdk1.7和jdk1.6的Collections.sort方法不一样
- 关于工程师文化
- iOS 全局修改UINavigation 后退按钮
- 动态修改UINavigationBar的背景色
- 异步图片上传
- 信用卡:银联,VISA,MasterCard
- 笨拙而诡异的 Oracle(之二)
- jdk1.7和jdk1.6的Collections.sort方法不一样
- magento中如何实现产品图片放大效果
- 生成解析sqlite DB文件笔记
- HDFS文件读取流程
- svn与git结合,实现版本管理
- Android的gps的代码分析(四)
- Android的GPS的代码分析(五)
- Spring 之注解事务 @Transactional