"To open IE browser steps with Selenium":
1, run the test script on IE browser, first need to download IEDriverServer.exe, put in IE browser's installation directory and the same sibling directory.
2. The reference code is as follows:
ImportOrg.junit.After;ImportOrg.junit.Before;Importorg.junit.Test;Importorg.openqa.selenium.By;ImportOrg.openqa.selenium.JavascriptExecutor;ImportOrg.openqa.selenium.WebDriver;Importorg.openqa.selenium.WebElement;ImportOrg.openqa.selenium.ie.InternetExplorerDriver;Importorg.openqa.selenium.support.ui.ExpectedCondition;Importorg.openqa.selenium.support.ui.WebDriverWait;ImportCom.gargoylesoftware.htmlunit.javascript.background.JavaScriptExecutor;Importcom.thoughtworks.selenium.webdriven.commands.WaitForCondition; Public classseleniumtest{PrivateWebdriver Driver; @Before Public voidsetUp () {System.setproperty ("Webdriver.ie.driver", "C:\\Program Files (x86) \\Internet Explorer\\iedriverserver.exe"); Driver=NewInternetexplorerdriver (); System.out.println ("Open Browser"); } @Test Public voidtestlogic () {System.out.println ("Open and Baidu"); Driver.get ("http://www.baidu.com/"); webdriverwait wait=NewWebdriverwait (Driver, 10); webelement kw= Wait.until (NewExpectedcondition<webelement>() { Publicwebelement Apply (webdriver driver) {returnDriver.findelement (By.id ("kw")); } }); Try { if(kw!=NULL) {Kw.sendkeys ("Selenium"); Driver.findelement (By.id ("Su") . Click (); Thread.Sleep (1000); } System.out.println (Driver.getcurrenturl ()); Javascriptexecutor JS=(javascriptexecutor) driver; Js.executescript ((function () {var q=document.documentelement.scrolltop=10000);}) ()"); Thread.Sleep (10000000); } Catch(interruptedexception e) {e.printstacktrace (); }} @After Public voidTearDown () {if(driver!=NULL) {driver.quit (); } }}
"Problems encountered and their solutions":
1. Error:java.lang.IllegalStateException:The path to the driver executable must is set by the Webdriver.ie.driver system Prope Rty; For more information, see http://code.google.com/p/selenium/wiki/InternetExplorerDriver. The latest version can downloaded from http://selenium-release.storage.googleapis.com/index.html
Workaround:Set Systemproperty:system.setproperty ("Webdriver.ie.driver", "C:\\Program Files (x86) \\Internet Explorer\\iedriverserver.exe "); 2. Error:org.openqa.selenium.remote.SessionNotFoundException:Unexpected Error Launching Internet Explorer. Protected Mode settings is not the same for all zones. Enable Protected Mode must is 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.15 secondsbuild info:version: ' 2.41.0 ', Revision: ' 3192d8a ', Time: ' 2014-03-27 17:18:15 ' Sy Stem info:host: ' pc-201wegfer ', IP: ' 10.1.9.173 ', Os.name: ' Windows 7 ', Os.arch: ' AMD64 ', os.version: ' 6.1 ', java.version : ' 1.6.0_43 ' Driver info:org.openqa.selenium.ie.InternetExplorerDriver at Sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method)
Workaround:
IE security is removed:
Internet Options--security
internet-enable protected Mode tick remove
Local internet-enable protected mode tick remove
Trusted sites-Enable protected mode tick off
In addition to the above, you need to remove enable protected mode at Restricted sites
selenium-Open IE browser encounters a problem record