Do you need an extension while running your Selnium scripts?
Though I am not able to find a good use case when we’ll need an extension while running our automation Selenium scripts, but in case, you need an extension while running your SE scripts, here’s how you can do it:Step 1) Download Your Chrome Extension. To do this, get your webstore URL from the Google Web Store like “https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en“
Step 2) Then go to http://crxextractor.com/ and enter the Chrome web store URL from Step 1 in the URL field to download the .crx file of the required extension.
Step 3) Once you have the .crx file of that extension, it’s time to save it somewhere so that you can use it in your Selenium script.
Step 4) Use the addExtensions method of the ChromeOptions class in your Selenium script.
Sample code:
And in Selenium 4, we have a direct method installExtension and uninstallExtension for the Firefox Driver. The installExtension installs a new addon with the current session which in turn will return an ID that may later be used to uninstallExtension the addon using uninstallAddon.