How to Access Firefox Extension I Added in Selenium Webdriver

How to access Firefox Extension I added in Selenium Webdriver?

It depends on extension. Usually the extension's behaviour can be to some extent controlled by setting appropriate properties (the ones you can find in about:config) when creating an FF profile. For instance to have Firebug window open by default after FF starts I would include the following line in my code:

default_profile["extensions.firebug.allPagesActivation"] = true

The extensions I use usually have some kind of auto-export feature that automatically sends data to server or saves it on disk. I am afraid there is no way of controlling an extension with WebDriver so not all extensions will be usable in automated tests.

How to add extension in firefox driver in Java using selenium

Try with FF68,selenium-java 4.0.0-alpha-2 and v0.24.0 . Tested on Windows machine.

FirefoxProfile profile = new FirefoxProfile();

profile.addExtension(new File("foxyproxy_basic-5.5-an+fx.xpi"));

options.setProfile(profile);

Is there a way to add extension on startup firefox with selenium on nodejs?

With the latest version I could get this to work.

However, I think firefox.Profile has been removed as now it will by default run with an anonymous profile (see https://www.selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/firefox)

E.g. in my example below I take a screenshot which shows the dark reader extension working.

const {Builder} = require('selenium-webdriver');
const fs = require('fs');
const firefox = require('selenium-webdriver/firefox');

(async function example() {
let options = new firefox.Options().addExtensions('dark_reader-4.9.32-an+fx.xpi');

let driver = await new Builder()
.forBrowser('firefox')
.setFirefoxOptions(options)
.build();

try {
await driver.get('https://google.com/');

await new Promise(resolve => setTimeout(resolve, 5000));
const image = await driver.takeScreenshot();
fs.writeFileSync('out.png', image, { encoding: 'base64' })

} finally {
await driver.quit();
}
})();


Related Topics



Leave a reply



Submit