报错信息如下:

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时,还需要一个插件:IEDriverServer.exe。(去这个地址下载就可以:http://vdisk.weibo.com/s/avYXJnY3vlyox)

下载之后将其放在IE的安装目录下:

 

接下来打开IE浏览器,设置->Internet选项->安全,如下图:

需要分别将四个区域的“启用保护模式”的勾取消掉,设置好点击确定。

还需要在项目中增加一段代码:

System.setProperty("webdriver.ie.driver","C:/Program Files/Internet Explorer/IEDriverServer.exe");

完整代码如下:

 

 

 

对了还有,刚才浏览器设置后忘记点确定,然后报了这个错:

Started InternetExplorerDriver server (32-bit)
2.35.3.0
Listening on port 16254
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: 3.32 seconds
Build info: version: '2.45.0', revision: '32a636c', time: '2015-03-05 22:01:35'
System info: host: 'Administrator', ip: '192.168.91.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_80'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver

意思就是浏览器保护模式设置不一致所致,

所以这里也需要注意。

 

posted on 2018-09-06 15:37  向日葵盛开的地方  阅读(282)  评论(0编辑  收藏  举报