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 ...
 - c# 双问号运算
			
model.id??0 ??运算:如果运算符左边的值为NULL侧返回右边的值,否则返回左边的值
 - iOS GCD多线程介绍
			
GCD:是纯C语言写的,是苹果公司为多核的并行运算提出的解决方案. GCD的两个核心概念: - 任务 - 队列 将任务添加到队列中 GCD会自动将队列中的任务取出,放到对应的线程中执行 任务的取出遵循 ...
 - 在Mac OS上搭建本地服务器
			
我们在做网络编程的时候一般是需要有网络环境的,这样可以边写边测试达到很高的效率.但有些时候我们由于很多原因我们的电脑无法连接到网络,这时就会感觉很不自在,所以今天在这里教大家怎么用自己电脑作服务器. ...
 - ASIHttpRequest网络请求第三方类库使用方法详解
			
一. 第一步首先你要从网络上下载ASIHttpRequestlib, 下载以后解压,增加到你的工程里面, 这个时间检查工程内部是否已经导入成功,文件结构如下: ASIHTTPRequestConfig ...
 - OA系统权限管理设计方案学习
			
学习之:http://www.cnblogs.com/kivenhou/archive/2009/10/19/1586106.html 此为模型图: 据此写了sql语句: drop table if ...
 - <select>与<datalist>的区别
			
size:下拉框中每次出现选项的个数 multiple:可以一次性选多个选项: disabled:时下拉框不可用,无法点击选项 list:它的值应于id的值对应 datalist要与input标签一 ...
 - 浅谈Chrome V8引擎中的垃圾回收机制
			
垃圾回收器 JavaScript的垃圾回收器 JavaScript使用垃圾回收机制来自动管理内存.垃圾回收是一把双刃剑,其好处是可以大幅简化程序的内存管理代码,降低程序员的负担,减少因 长时间运转而带 ...
 - Cookie的基本使用
			
1, 如何创建cookie <?php //创建cookie信息 //这个函数用于保存cookie //第一个参数,表示cookie一个key,第二个表示val,第三个表示cookie值,在客户 ...
 - 4种检测是否支持HTML5的方法,你知道几个?
			
4种检测是否支持HTML5的方法,你知道几个? 1,检查特定的属性是否存在于全局的对象里面,比如说window或navigator. 比如geolocation,它是HTML5新加支持的新特性:它是由 ...