Selenium WebDriver使用IE浏览器
摘:http://www.cnblogs.com/dream0577/archive/2012/10/07/2714579.html
/**
用IE驱动,1.先到官网下载IEDriverServer.exe,2.在代码设置属性 3.在代码设置忽略IE保护模式,4.import org.openqa.selenium.remote.DesiredCapabilities;
*/
System.setProperty("webdriver.ie.driver", "F:\\selenium\\workspace\\fj10086\\IEDriverServer.exe");
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
driver = new InternetExplorerDriver(ieCapabilities);
Selenium WebDriver使用IE浏览器
前文写到了WebDriver和JUnit的基本使用,是以Firefox为例来写的,而当我使用IE浏览器Driver来使用WebDriver时,遇到了一些问题,故记录如下。
如下的Java代码是打开IE浏览器,然后在Google中搜索“smilejay”关键字。
1 |
package com.selenium.test; |
上面的代运行行是没有错误的,不过,类似的程序,如果没有写的很好,或IE浏览器环境没设置好,在Eclipse中可能会遇到如下的一些错误提示。
1. 需要设置IE的Driver到“webdriver.ie.driver”变量中,否则可能遇到报错信息:
1 |
The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see http://code.google.com/p/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://code.google.com/p/selenium/downloads/list |
更具提示,需要添加IEDriverServer.exe(从Selenium官网可下载的),并用如下的代码进行设置。
System.setProperty(“webdriver.ie.driver”,”C:\\Users\\yren9\\workspace\\selenium\\IEDriverServer.exe”);
2. 如果IE浏览器设置安全性较高,在“Internet Options”中都不要选择“Enable Protected Mode”(保护模式),否则可能遇到如下的错误提示。
1 |
Started InternetExplorerDriver server (64-bit) |
解决方法有两种,一种是修改掉IE的设置,不要在任何情况下使用保护模式(protected mode),另一种即是前面代码中如下片段在运行时设置IE的Capabilities。
1 |
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer(); |
3. 即便是我上面已经修改好的代码(解决了1、2两个问题),在Eclipse中也会有如下的一些运行时警告(我的Win7上的IE9有这个问题),社区上有人也反映了这个问题,但是对测试程序运行时的功能没有影响,作为一个warning,而没有啥好的解决方法。
1 |
Started InternetExplorerDriver server (64-bit) |
关于这个的一个讨论话题: https://code.google.com/p/selenium/issues/detail?id=2568
Selenium WebDriver使用IE浏览器的更多相关文章
- selenium webdriver启动Chrome浏览器后无法输入网址的解决办法
通过selenium webdriver启动Chrome浏览器,脚本如下: from selenium import webdriver browser = webdriver.Chrome() br ...
- selenium webdriver启动IE浏览器失败的解决办法
通过selenium webdriver启动IE浏览器失败,报错:selenium.common.exceptions.WebDriverException: Message: Unexpected ...
- selenium webdriver 启动三大浏览器Firefox,Chrome,IE
selenium webdriver 启动三大浏览器Firefox,Chrome,IE 1.安装selenium 在联网的情况下,在Windows命令行(cmd)输入pip install selen ...
- selenium webdriver操作各浏览器
描述 本文主要是针对Chrome 62 , firefox57 ,和IE11 三个版本的操作.相关的driver .可点击以下链接.所有的driver 建议放在浏览器的目录下,本文中所有的driver ...
- Selenium WebDriver的多浏览器测试
1. IE浏览器,需要配合下载IEDriverSever.exe的驱动程序,目前selenium支持IE9以上. (驱动程序下载链接:https://pan.baidu.com/s/1YpaUsIs1 ...
- Selenium webdriver 操作chrome 浏览器
Step1: 下载chromedriver. 下载路径: http://chromedriver.storage.googleapis.com/index.html 选择一个合适的下载即可.我下载的是 ...
- Selenium webdriver 操作IE浏览器
V1.0版本:直接新建WebDriver使用 import org.openqa.selenium.WebDriver; import org.openqa.selenium.ie.InternetE ...
- Python+Selenium WebDriver API:浏览器及元素的常用函数及变量整理总结
由于网页自动化要操作浏览器以及浏览器页面元素,这里笔者就将浏览器及页面元素常用的函数及变量整理总结一下,以供读者在编写网页自动化测试时查阅. from selenium import webdrive ...
- selenium webdriver python 操作浏览器
新建driver driver=webdriver.Firefox() driver=webdriver.Ie() driver=webdriver.Chrome() 打开一个链接 driver. ...
随机推荐
- node js 调试
npm install -g node-inspector node --debug app.js >重新打开一个窗口 node-inspector & KO! no ...
- ie6并不是不支持!important
之前对ie6接触不多,并且认识也不深,虽然知道ie6中的!important很特别,但是并没有记住特别在哪里~今天就记录一下吧! 首先,很多人说ie6是不支持!important的,其实这个一个错误的 ...
- 【转】提高VR渲染速度的最好方法(经典转载)
VR的基本渲染方法掌握起来并不难,但是最迫切需要解决的问题是VR的出图速度问题.动则需要数小时的渲染时间真的是很难以接受,我们从三个影响速度的参数结合网上一些高手的教程来分析一下. 一.Irradia ...
- C++学习基础九——继承
1.不同于Java中通过extends实现继承,C++是通过:实现的. 2.C++中同样包含public,private,protected三个关键字: public关键字表示在任意其他类中可调用该成 ...
- HashMap的面试总结(摘抄)
HashMap的工作原理是近年来常见的Java面试题.几乎每个Java程序员都知道 HashMap,都知道哪里要用HashMap,知道HashTable和HashMap之间的区别,那么为何这道面试题如 ...
- -Dmaven.multiModuleProjectDirectory system propery is not set问题解决
-Dmaven.multiModuleProjectDirectory system propery is not set问题解决 eclipse中使用maven插件的时候,运行run as mave ...
- 循序渐进之Spring AOP(5) - 创建切面
在掌握了可用的增强后,接下来要做的就是精确的描述切点.前面的示例都是指定一个目标类并把增强织入到所有方法中,实际开发显然会有更精细的筛选需求,比如对所有类中名称以test结尾的方法加入监控执行时间,或 ...
- swift 代码添加image
let image_ElectricianBtn = UIImage(named: "ElectricianBtn") let vimage_ElectricianBtn = UI ...
- 如何用expdp、impdp按表空间导出、导入?
参考:http://blog.csdn.net/zftang/article/details/6387325 A数据库: 表空间:ylcois 用户名:ylcois 密码:ylcois B数据库: 表 ...
- java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.TextView
最近在学习drawerLayout时,遇到这个bug.如下示: java.lang.ClassCastException: android.widget.RelativeLayout cannot b ...