I'm not able to launch IE browser to run my selenium automated tests written in Java. I'm using Windows 7 and IE 9. Below is my code:
Please find the attachment.
public class GoogleNews {
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
ArrayList al = new ArrayList();
@Before
public void setUp() throws Exception {
//driver = new FirefoxDriver();
driver =new InternetExplorerDriver();
baseUrl = "https://news.google.co.in/";
}
@Test
public void testApple() throws Exception {
driver.get(baseUrl);
}
}
It needs to set same Security level in all zones. To do that follow the steps below:
Finally, set Zoom level to 100% by right clicking on the gear located at the top right corner and enabling the status-bar. Default zoom level is now displayed at the lower right.
Well as the stack trace says, you would need to set the protected mode settings to same for all zones in IE. Read the why here : http://jimevansmusic.blogspot.in/2012/08/youre-doing-it-wrong-protected-mode-and.html
and a quick how to from the same link : "In IE, from the Tools menu (or the gear icon in the toolbar in later versions), select "Internet options." Go to the Security tab. At the bottom of the dialog for each zone, you should see a check box labeled "Enable Protected Mode." Set the value of the check box to the same value, either checked or unchecked, for each zone"
To resolve this issue you have to do two things :
You will need to set a registry entry on the target computer so that the driver can maintain a connection to the instance of Internet Explorer it creates.
Change few settings of Internet Explorer browser on that machine (where you desire to run automation).
1 . Setting Registry Key / Entry :
To set registry key or entry, you need to open "Registry Editor".
To open "Registry Editor" press windows button key + r alphabet key which will open "Run Window" and then type "regedit" and press enter.
Or Press Windows button key and enter "regedit" at start menu and press enter. Now depending upon your OS type whether 32/64 bit follow the corresponding steps.
Windows 32 bit : go to this location - "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl" and check for "FEATURE_BFCACHE" key.
Windows 64 bit : go to this location - HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl and check for "FEATURE_BFCACHE" key. Please note that the FEATURE_BFCACHE subkey may or may not be present, and should be created if it is not present.
Important: Inside this key, create a DWORD value named iexplore.exe with the value of 0.
2 . Change Settings of Internet Explorer Browser :
Click on setting button and select "Internet options".
On "Internet options" window go to "Security" tab
Now select "Internet" option and unchecked the "Enable Protected Mode" check box and change the "Security level" to low.
Now select "Local Intranet" Option and change the "Security level" to low.
Now select "Trusted Sites" Option and change the "Security level" to low.
Before you start with Internet Explorer and Selenium Webdriver Consider these two important rules.
How to set this?
Method 1:
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
This will definetly not show any error and browser will open and also will navigate to the URL.
BUT This will not identify any element and hence you can not proceed.
Why? Because we have simly suppressed the error and asked IE to open and get that URL. However Selenium will identify elements only if the browser zoom is 100% ie. default. So the final code would be
Method 2 The robust and full proof way:
Hope this helps. Do let me know if further information is required.
The following snippet of WebDriver Java code should work to launch IE. The code will ignore the setup of Protected mode settings for all zone in the IE browser.
Download IEDriverServer and extract it into your desired location and set the absolute path (In my above example it was "D:\Ripon Al Wasim\IEDriverServer.exe")
Rather than using Absolute path for IEDriverServer.exe, its better to use relative path in accordance to the project.