My Thoughts: September 2013

Saturday, September 21

org.openqa.selenium.remote.SessionNotFoundException:Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones.

Sometimes when we are trying to load InternetExplorer from WebDriver we will get below error :

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: 1.39 seconds
Build info: version: '2.34.0', revision: '11cd0ef', time: '2013-08-06 17:11:28'
System info: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.7.0_09'
Driver info: 

This error is because of the security settings in IE. There is a permanent fix to this. :P

>> Open IE , then go to Tools>>Security tab .

>>Now either check or uncheck the "Enable Protected Mode" checkbox for all zones i.e Internet , Local internet, Trusted Sites, Restricted Sites.

We are done . Now start running your script , it will go great  without any issues :) 

Thursday, September 12

Seleinum Webdriver - Loading chrome browser with default extension

When we start chrome browser using webdriver then by default it will load with out any extensions. But we can also load chrome browser with some default extensions if we need . To do this we need to know .crx file path of chrome extension. Here are the steps to find out the .crx file path :

1.Open chrome browser and type chrome://extensions/ . Now note down the extension id that you would like to be loaded when your browser starts.

2.Check the "Developer Mode" checkbox.Now you will see "Pack Extension" button .

3.Go to Extenstion folder of chrome .You will see the list of other folders with unique id's. Go to folder with the id , which you got in Step 1. Go deep into the folder until you find the manifest.json file and then copy the location .
3.Click on "Pack Extension" button and enter the path of folder in which extension manifest.json file is located.

Click on Pack Extension button.

4.We will get confirmation alert which displays the path of .crx file of extension. Copy that path and use it in your script

Thats it. Now we are done with the .crx file path . Use that path in the below code to load chrome browser with the default extension.
	import org.openqa.selenium.WebDriver;
    import org.testng.annotations.Test;

	public class Chrome {

		WebDriver  driver;  
		public void start(){	
			ChromeOptions options = new ChromeOptions();		
			options.addExtensions(new File("CRX FILE PATH"));
			System.setProperty("","PATH of chromedriver.exe");
			ChromeDriver driver = new ChromeDriver(options);