首页 > 代码库 > Selenium2.0之WebDriver的启用IE10(IEDriverServer)

Selenium2.0之WebDriver的启用IE10(IEDriverServer)

如图技术分享 代码:

package org.coderinfo.demo;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
 
public class StartBrowser {
public static void main(String[] args) {
/* 如何使用IE浏览器
* 如果没有将IEDriverServer放入系统的环境变量中,那么必须在程序中设置 例如:
* System.setProperty("webdriver.ie.driver",* "IEDriverServer.exe文件存放的路径"* );
*/
  System.setProperty("webdriver.ie.driver","C:\\Program Files\\Internet Explorer\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("http://192.168.4.20/yocalyAdmin/login.jsp");
}
}
报错:
Started InternetExplorerDriver server (32-bit)
2.45.0.0
Listening on port 19529
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. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.20 seconds
Build info: version: ‘2.45.0‘, revision: ‘5017cb8‘, time: ‘2015-02-27 00:00:10‘
System info: host: ‘WangHuan-PC‘, ip: ‘172.168.230.108‘, os.name: ‘Windows 7‘, os.arch: ‘x86‘, os.version: ‘6.1‘, java.version: ‘1.6.0_43‘
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:162)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:225)
at org.openqa.selenium.ie.InternetExplorerDriver.run(InternetExplorerDriver.java:182)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:174)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:146)
at org.coderinfo.demo.StartBrowser.main(StartBrowser.java:13)
解决方案:
1.配置系统环境变量。
我的电脑--》右键——》属性——》高级系统设置——》环境变量——》系统变量——》path
注:先把IEDriverServer.exe放在C:\Program Files\Internet Explorer根目录里,再把这个路径放到path里。
技术分享
 2.关闭IE的启用保护模式
打开IE——》设置——》Internet选项——》安全——》去掉启用保护模式前的对勾
技术分享
总结:当两者都做了,再运行例子,就会成功。
本人也是菜鸟,不过喜欢总结。
 
转自:huan12_8 莫回头,往前走
http://blog.163.com/huan12_8/blog/static/130519090201551224153951/

Selenium2.0之WebDriver的启用IE10(IEDriverServer)