Adding Browser Extentions with Selenium WebDriver


Adding Browser Extentions with Selenium WebDriver

When Selenium WebDriver launch a browser , it creates a new profile or options set with browser’s default features.This launched browser does not contain addons or extentions.In everytime we need to add on , which addon or extention we want to use.

Chrome

1
2
3
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addExtensions( new File( "/path/to/extension.crx" )) ;
driver = new ChromeDriver(chromeOptions);

Firefox

1
2
3
4
5
FirefoxProfile profile = new FirefoxProfile() ; 
profile.addExtension( new File( "/path/to/addon.xpi" )) ;
FirefoxOptions firefoxOptions = new FirefoxOptions() ;
firefoxOptions.setProfile(profile) ;
FirefoxDriver driver = new FirefoxDriver(firefoxOptions) ;