1.selenium中启动ie浏览器代时码(红框中)如下 :
点击运行时,控制台报错如下:
Started InternetExplorerDriver server (64-bit)
2.53.0.0
Listening on port 31574
Only local connections are allowed
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: 692 milliseconds
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'XL-20150414QGDQ', ip: '192.168.80.6', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_80'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:234)
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 Project1Class.main(Project1Class.java:13)
解决方法:
解决方法有两种,一种是修改掉IE的设置,不要在任何情况下使用保护模式(protected mode),另一种即是在前面代码中如下片段在运行时设置IE的Capabilities。
添加后代码如下:
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
WebDriver driver = new InternetExplorerDriver(ieCapabilities);
提示错误信息可参考如下地址:https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver.
The latest version can be downloaded from http://selenium-release.storage.googleapis.com/index.html
2.关于下拉框的定位法 :
方法一:如果该下拉框是html原生的select ,则可用selenium的select方法定位; 但是如果是自己开发的下拉框,则不能用该方法。
Select selectCategory1 = new Select(driver.findElement(By.id("category_1")));
selectCategory1.selectByVisibleText("java");
Select selectCategory2 = new Select(driver.findElement(By.id("category_2")));
selectCategory2.selectByVisibleText("3D游戏");
Select selectCategory3 = new Select(driver.findElement(By.id("difficulty")));
selectCategory3.selectByVisibleText("中级");
否则将会报如下错误:
3.关于编辑器中文本框的定位问题,在<frame>里,但找不到任何可定位的元素,待解决。