Selenium webdriver 操作IE浏览器
V1.0版本:直接新建WebDriver使用
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver; public class IETest {
public static void main(String[] args) {
WebDriver wd = new InternetExplorerDriver();
wd.get("http://www.baidu.com");
try {
Thread.sleep(1200);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(wd.getCurrentUrl());
wd.quit(); }
}
结果:运行出错
Exception in thread "main" java.lang.IllegalStateException: 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://selenium-release.storage.googleapis.com/index.html
分析:selenium找不到IE Driver。
V2.0版本:使用IEDriverServer
Step1: 下载IEDriverServer。
下载路径:http://selenium-release.storage.googleapis.com/index.html
我下载的是2.48版本的IEDriverServer_Win32_2.48.0.zip ,解压之后得到IEDriverServer.exe 。打开2.48,可以看到两个IEDriverServer:
32bit: IEDriverServer_Win32_2.48.0.zip
64bit: IEDriverServer_x64_2.48.0.zip
选择一个合适的下载即可。
Step2: 放置IEDriverServer
在跟项目包平行的地方新建一个包,比如”lib",然后将 IEDriverServer.exe拷贝到lib下。

Step3: 添加 webdriver.ie.driver 属性设置
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver; public class IETest { public static void main(String[] args) {
System.setProperty("webdriver.ie.driver","src/lib/IEDriverServer.exe");
WebDriver wd = new InternetExplorerDriver();
wd.get("http://www.baidu.com");
try {
Thread.sleep(1200);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(wd.getCurrentUrl());
wd.quit(); }
}
结果:运行出错
Started InternetExplorerDriver server (32-bit)
2.48.0.0
Listening on port 38600
Exception in thread "main" org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones.
分析:微软自IE7后加入了Protected Mode(保护模式)
V3.0版本:更改保护模式
Step1: Win+R打开“运行”,输入“regedit.exe",打开注册表
Step2: 找到HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones
Step3: 可以看到5个文件夹,分别为: 0 1 2 3 4 。
在1-4号Key下面都有名叫2500的属性,则将其值改为相同的非零值。一般情况下,系统上默认的是1,2号key 2500属性值为3,3,4号key 2500属性为0,将3,4号key的值该成3就可以。
Step4: 点击“应用”,“确定”,使更改生效。
Step5: 重新运行上面的程序。
结果: 运行通过
Started InternetExplorerDriver server (32-bit)
2.48.0.0
Listening on port 41898
https://www.baidu.com/
Selenium webdriver 操作IE浏览器的更多相关文章
- selenium webdriver操作各浏览器
描述 本文主要是针对Chrome 62 , firefox57 ,和IE11 三个版本的操作.相关的driver .可点击以下链接.所有的driver 建议放在浏览器的目录下,本文中所有的driver ...
- Selenium webdriver 操作chrome 浏览器
Step1: 下载chromedriver. 下载路径: http://chromedriver.storage.googleapis.com/index.html 选择一个合适的下载即可.我下载的是 ...
- Selenium WebDriver使用IE浏览器
摘:http://www.cnblogs.com/dream0577/archive/2012/10/07/2714579.html /** 用IE驱动,1.先到官网下载IEDriverS ...
- 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——操作隐藏的元素(三)switchTo().frame()
在web 应用中经常会遇到frame 嵌套页面的应用,页WebDriver 每次只能在一个页面上识别元素,对于frame 嵌套内的页面上的元素,直接定位是定位是定位不到的.这个时候就需要通过switc ...
- Selenium Webdriver——操作隐藏的元素(二)display属性
有时候我们会碰到一些元素不可见,这个时候selenium就无法对这些元素进行操作了.例如,下面的情况: 页面主要通过“display:none”来控制整个下拉框不可见.这个时候如果直接操作这个下拉框, ...
- Selenium Webdriver——操作隐藏的元素
有时候我们会碰到一些元素不可见,这个时候selenium就无法对这些元素进行操作了.例如,下面的情况: 页面主要通过“display:none”来控制整个下拉框不可见.这个时候如果直接操作这个下拉框, ...
随机推荐
- js中浮点型运算 注意点
先看张图: 这是一个JS浮点数运算Bug,导致我树状图,数据合计不正确,,,,,,两个小数相加,出来那么多位小数 (这是修该之后的) 网上找到以下解决方式: 方法一:有js自定义函数 <sc ...
- SQLSERVER 触发器 将一个服务器上的数据库中数据插入到另一个服务器上的数据库中怎么做
首先要执行 sp_addlinkedserver '服务器ip' 然后开始写语句 insert into ip.库名字.dbo.table select * from iserted
- power desinger 学习笔记<一>
如果一张表有 很多字段(多于30个),那么一个一个复制粘贴,耗时耗力.可以偷懒,事先编辑好 sql脚本,然后把sql脚本导入 power designer,是不是很方便? 看下面的 1. 打开Pow ...
- 查看Jquery版本
1. $.fn.jquery > "1.11.1" 2. 通过这样可以 判断一个对象是否是jquery对象!!
- php中文乱码
一. 首先是PHP网页的编码 1. php文件本身的编码与网页的编码应匹配 a. 如果欲使用gb2312编码,那么php要输出头:header(“Content-Typ ...
- PHP随机生成指定时间段的指定个数时间
/** * 生成某个范围内的随机时间 * @param <type> $begintime 起始时间 格式为 Y-m-d H:i:s * @param <type> $endt ...
- DOS命令行使用pscp实现远程文件和文件夹传输(转)
转自 http://snailwarrior.blog.51cto.com/680306/141201 pscp是putty安装包所带的远程文件传输工具,使用和Linux下scp命令相似,具体的使 ...
- 简单学C——第一天
基本功 一.数据类型: 在C语言中,有数据类型这一说法.为何有这一说法?是因为在现实生活中存在着不同的数据,(例如整数,小数,字符即a b c d , . ; " 之类).由于计算机中所有 ...
- Josephus2
约瑟夫问题升级问题 编号为1~N的N个人按顺时针方向围坐一圈,每个人持有一个密码(正整数,可以自由输入),开始人选一个正整数作为报数上限值M,从第一个人按顺时针方向自1开始顺序报数,报道M是停止报数. ...
- ios CAF音频转换为MP3
Url:http://blog.csdn.net/ysy441088327/article/details/7392842#reply 为了达到 iPhone 与 Android 实现音频互通. 那么 ...