Selenium webdriver using IE browser

Source: Internet
Author: User

Transferred from: http://smilejay.com/2012/09/selenium-webdriver-with-ie/

The Java code below is to open IE browser and then search Google for the "smilejay" keyword.

[Copy to clipboard]View Code JAVA
1234567891011121314151617181920212223242526272829303132333435363738
Package Com.selenium.test; import Org.openqa.selenium.ie.internetexplorerdriver;import Org.openqa.selenium.remote.desiredcapabilities;import Org.openqa.selenium.by;import Org.openqa.selenium.webdriver;import Org.openqa.selenium.webelement; public class TempGoogle {public static    void Main (string[] args) {final String sURL = "http://www.google.com.hk/";    System.setproperty ("Webdriver.ie.driver", "C:\\users\\yren9\\workspace\\selenium\\iedriverserver.exe");    Desiredcapabilities iecapabilities = Desiredcapabilities.internetexplorer ();    Iecapabilities.setcapability (internetexplorerdriver.introduce_flakiness_by_ignoring_security_domains,true);    Webdriver owebdriver = new Internetexplorerdriver (iecapabilities);    Owebdriver.get (sURL); try {thread.sleep;} catch (Interruptedexception e) {//TODO auto-generated catch Blocke.printstacktrace ();}//Use n    Ame Locator to identify the search input field. Webelement Osearchinputelem = owebdriver.findelement (By.name ("Q"));    Osearchinputelem.sendkeys ("Smilejay");      Webelement ogooglesearchbtn = owebdriver.findelement (By.xpath ("//input[@name = ' btnk ']");    Ogooglesearchbtn.click ();  try {thread.sleep (5000);    } catch (Interruptedexception ex) {System.out.println (Ex.getmessage ()); }  owebdriver.close ();}}




The above generation runs the line without errors, however, similar programs, if not written well, or IE browser environment is not set, in eclipse may encounter some of the following error prompts.
1. You need to set the driver of IE to "webdriver.ie.driver" variable, otherwise you may encounter error message:

[Copy to clipboard]View Code JAVA
123
The path to the driver executable must is set by the Webdriver.ie.driver system property; For more information, see Http://code.google.com/p/selenium/wiki/InternetExplorerDriver. The latest version can downloaded from http://code.google.com/p/selenium/downloads/list2012-9-2 16:09:02 Org.openqa.selenium.ie.InternetExplorerDriverServer Initializelib Warning: This method of starting the IE driver is deprecated And would be removed in selenium 2.26.  Download the IEDriverServer.exe from http://code.google.com/p/selenium/downloads/list and ensure that it's in your PATH.

More hints, you need to add IEDriverServer.exe (downloadable from the Selenium website), and set it up with the following code.
System.setproperty ("Webdriver.ie.driver", "C:\\users\\yren9\\workspace\\selenium\\iedriverserver.exe");

2. If Internet Explorer settings are high security, do not select Enable Protected mode in the Internet options, or you may experience the following error message.

[Copy to clipboard]View Code JAVA
12345678910111213141516171819202122
Started internetexplorerdriver Server (64-bit) 2.25.2.0Listening on port 40961Exception in thread "main" org.openqa.selenium.WebDriverException: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.18 secondsbuild info:version: ' 2.25.0 ', Revision: ' 17482 ', Time: ' 2012-07-18 22:18:01 ' Syst Em info:os.name: ' Windows 7 ', Os.arch: ' x86 ', os.version: ' 6.1 ', java.version: ' 1.6.0_29 ' Driver info:driver.version:Int Ernetexplorerdriversession Id:01e30b64-e403-440c-bed8-4859ef2128f9at 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:188) at Org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed (errorhandler.java:145) at Org.openqa.selenium.remote.RemoteWebDriver.execute (remotewebdriver.java:498) at Org.openqa.selenium.remote.RemoteWebDriver.startSession (remotewebdriver.java:182) at Org.openqa.selenium.remote.RemoteWebDriver.startSession (remotewebdriver.java:167) at Org.openqa.selenium.ie.InternetExplorerDriver.startSession (internetexplorerdriver.java:133) at Org.openqa.selenium.ie.InternetExplorerDriver.setup (internetexplorerdriver.java:106) at Org.openqa.selenium.ie.internetexplorerdriver.<init> (internetexplorerdriver.java:52) at Com.selenium.test.TempGoogle.main (tempgoogle.java:15)

There are two workarounds, one is to modify the settings of IE, do not use protected mode under any circumstances (Protected mode), the other is the previous code in the following fragment set IE at runtime capabilities.

[Copy to clipboard]View Code JAVA
123
Desiredcapabilities iecapabilities = Desiredcapabilities.internetexplorer (); Iecapabilities.setcapability ( Internetexplorerdriver.introduce_flakiness_by_ignoring_security_domains,true); Webdriver owebdriver = new Internetexplorerdriver (iecapabilities);



3. Even if I have modified the code above (solve 1, 22 problems), there will be some of the following runtime warnings in Eclipse (IE9 on my Win7), some people in the community also reflect this problem, but there is no impact on the function of the test program runtime, As a warning, there is no good solution.

[Copy to clipboard]View Code JAVA
1234567
Started internetexplorerdriver Server (64-bit) 2.25.2.0Listening on port 449402012-9-2 16:58:19 Org.apache.http.impl.client.DefaultRequestDirector Tryexecute Info: I/O exception ( org.apache.http.NoHttpResponseException) caught when processing request:the target server failed to respond2012-9-2 16:5 8:19 Org.apache.http.impl.client.DefaultRequestDirector Tryexecute Info: Retrying request

A discussion on this topic: https://code.google.com/p/selenium/issues/detail?id=2568

Selenium webdriver using IE browser (GO)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.