Selenium webdriver Java 操作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 Java 操作IE浏览器的更多相关文章
- Selenium webdriver Java 操作chrome 浏览器
Step1: 下载chromedriver. 下载路径: http://chromedriver.storage.googleapis.com/index.html 选择一个合适的下载即可.我下载的是 ...
- selenium webdriver python 操作IE浏览器
Step1:下载IEDriverServer 下载路径:http://selenium-release.storage.googleapis.com/index.html 我下载的是2.48版本的IE ...
- selenium webdriver python 操作Chrome浏览器
Step1: 下载chromedriver. 下载路径: http://chromedriver.storage.googleapis.com/index.html 选择一个合适的下载即可.我下载的是 ...
- Selenium Webdriver java 积累一
Selenium Webdriver 学习: http://jarvi.iteye.com/category/203994 https://github.com/easonhan007/webdriv ...
- [selenium webdriver Java]常用api
1. 获取元素文本 WebElement类的getText()方法返回元素的innerText属性.所以元素里如果有子节点一样也会被返回出来.如下所示 public class GetText { @ ...
- Python脚本控制的WebDriver 常用操作 <七>浏览器前进和后退操作
下面将使用WebDriver来控制浏览器的前进和后退操作 测试用例场景 此操作和get.url()方法功能相同 Python脚本 # coding=gbk ''' Created on 2013年12 ...
- [selenium webdriver Java]元素定位——findElement/findElements
策略 语法 语法 描述 By id driver.findElement(By.id()) driver.findElements(By.id()) 通过id属性定位元素 By name driver ...
- selenium webdriver(3)---操作页面对象
页面对象的相关操作可以通过接口文件org.openqa.selenium.WebElement查看,本文只是对象接口的使用方式,具体的实现方式在org.openqa.selenium.remote.R ...
- Selenium WebDriver java 简单实例
开发环境 JDK 下载地址: http://www.oracle.com/technetwork/java/javase/downloads/index.html Eclipse: 下载地址:http ...
随机推荐
- hihocoder-第六十一周 Combination Lock
题目1 : Combination Lock 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview roo ...
- docker从零开始网络(五)null网络
禁用容器的网络连接 预计阅读时间: 1分钟 如果要完全禁用容器上的网络堆栈,可以--network none在启动容器时使用该标志.在容器内,仅创建环回设备.以下示例说明了这一点. 1.创建容器. [ ...
- ORACLE中通过DBMS_CRYPTO包对表敏感字段进行加密
http://doc.primeton.com/pages/viewpage.action?pageId=4917998
- 安装smartmontool报错:libc6-dev : 破坏:
https://blog.csdn.net/weixin_38705903/article/details/81947717
- 转怎么让VI支持中文显示
https://blog.csdn.net/kayneo/article/details/72957475
- C#关于log4net(Log For Net)
1 介绍 log4net(Log For Net)是Apache开源的应用于.Net框架的日志记录工具,详细信息参见Apache网站.它是针对Java的log4j(Log For Java ...
- 简单的curl抓取数据
工欲善其事,必先利其器,数据抓取同样也是如此,PHP数据抓取常用CURL. CURL是一个使用libcurl库与各类服务器进行通讯,支持很多协议,如HTTP.FTP.TELNET等. curl_ini ...
- Spring创建对象的原理
当容器启动时,首先会加载给定的配置文件,将配置文件逐行解析.当解析到bean标签时,根据class属性的值,通过反射调用创建对象. 将创建好的对象存储到Spring自身维护的Map当中.map中的ke ...
- JavaWEB开发框架:Shiro
通过了三个月的实习,在javaWEB开发的过程当中,学习到了一些新的知识,特此记录一下学习到的一种新的WEB开发当中常用的用户认证和授权的安全框架,Shiro. 首先,要先知道shiro这个框架主要在 ...
- STL模板整理 set
SET set作为一个容器也是用来存储同一数据类型的数据类型,并且能从一个数据集合中取出数据,在set中每个元素的值都唯一,而且系统能根据元素的值自动进行排序.应该注意的是set中数元素的值不能直接被 ...