java selenium ie_Selenium webdriver Java 操作IE浏览器

V1.0版本:直接新建WebDriver使用

importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.ie.InternetExplorerDriver;public classIETest {public static voidmain(String[] args) {WebDriver wd= newInternetExplorerDriver();

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 fromhttp://selenium-release.storage.googleapis.com/index.html

分析:selenium找不到IE Driver。

V2.0版本:使用IEDriverServer

Step1: 下载IEDriverServer。

我下载的是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下。

dc60e4d9d82e91b5a70a130e056503a3.png

Step3: 添加 webdriver.ie.driver 属性设置

importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.ie.InternetExplorerDriver;public classIETest {public static voidmain(String[] args) {

System.setProperty("webdriver.ie.driver","src/lib/IEDriverServer.exe");

WebDriver wd= newInternetExplorerDriver();

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.0Listening on port38600Exception 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.0Listening on port41898https://www.baidu.com/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值