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 ...
随机推荐
- Plain Old Data (POD)
Plain Old Data (POD) POD指的是这样一些数据类型:基本数据类型.指针.union.数组.构造函数是 trivial 的 struct 或者 class. POD用来表明C++中与 ...
- request.getRequestDispatcher(url).forward(request, response)
request.getRequestDispatcher().forward(request, response) 意思是将客户端的请求转向到 getRequestDispatcher()方法中参数定 ...
- 曹政:CTO这点事
几乎整个互联网行业都缺 CTO,特别是一些草根背景的创业者,这个问题更加显著.从我自己的感受,身边各种朋友委托我找 CTO 的需求,嗯,算下来超过两位数了,光最近一个月就有 3 个,而且这三家都是刚拿 ...
- Java中的new关键字和引用传参
先看看Java中如何使用new关键字创建一个对象的. [java] view plain copy public class Student { public String name; public ...
- 记一次Laravel定时任务导致日志没有写入权限的坑
问题:用laravel开发定时任务时,发生了日志没有写入权限导致项目打不开的问题 原因:linux的添加定时任务时默认是当前登录用户,我定时任务会生成日志 crontab: kernel: 生成日志的 ...
- rhel 6.5 yum源的配置
https://blog.csdn.net/error_0_0_/article/details/54962199
- (转)Docker 基础 : Dockerfile
全文来自 Docker 基础 : Dockerfile Dockerfile 是一个文本格式的配置文件,用户可以使用 Dockerfile 快速创建自定义的镜像.我们会先介绍 Dockerfile 的 ...
- Codeforces 810 C. Do you want a date?
C. Do you want a date? time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- POJ 1703 Find them, Catch them【种类/带权并查集+判断两元素是否在同一集合/不同集合/无法确定+类似食物链】
The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the ...
- 数据排序 第二讲( 各种排序方法 结合noi题库1.10)
先来个题练练手吧! 例题 04:奖学金 查看 提交 统计 提问 总时间限制: 1000ms 内存限制: 65536kB 描述 某小学最近得到了一笔赞助,打算拿出其中一部分为学习成绩优秀的前5名学生 ...