My Thoughts: Seleinum Webdriver - Loading chrome browser with default extension

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);


No comments:

Post a Comment