需导入的支持类:
启动IE浏览器的代码:
System.setProperty("webdriver.ie.driver", IEDriverServer.exe的存放路径);
WebDriver driver = new InternetExplorerDriver();
driver.get("");
driver.quit(); //关闭浏览器
如果以上代码运行时提示类似于下图的错误提示:
如果做完以上所有操作后仍然无法启动IE浏览器,且有报类似于以下错误时Exception in thread “main” org.openqa.selenium.WebDriverException: 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)
System info: os.name: ‘Windows 7′, os.arch: ‘amd64′, os.version: ’6.1′, java.version: ’1.7.0_25′
则考虑是IE安全级别太高了,其解决方法是在internet选项中将安全级别设置成最低,同时取消对‘启用保护模式’的勾选;
做完了以上操作,IE便能顺利启动了