Add profile to Webdriver Firefox

Asked

Viewed 351 times

-1

Good morning I am automating a website, and to run some features it is necessary to use an extension in the browser. First I was trying to add the extension to the web driver with the

FirefoxOptions options = new FirefoxOptions();
options.addPreference("extensions.webextensions.ExtensionStorageIDB.migrated.websigner@softplan.com.br", true); 

Searching a little more, it seemed to me to be better to import a firefox profile when instantiating webDriver, I’m trying as follows

    FirefoxOptions options = new FirefoxOptions();
    FirefoxProfile firefoxProfile = new FirefoxProfile(
            new File("/home/henrique/.mozilla/firefox/r6eis7qo.automacao"));
    options.setProfile(firefoxProfile);
    System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/home/files/logsGeckodriver.txt");
    WebDriver driver = new FirefoxDriver(options);

but the webDriver is not instantiated, nor does it point to any error, when adding options.setCapability("marionette", false); it instantiates the webDriver, but without the desired profile

the "automation" profile is customized with the extension and the following preferences

    options.addPreference("browser.download.folderList", 2);
    options.addPreference("browser.download.dir", paramDownload);
    options.addPreference("browser.download.useDownloadDir", true);
    options.addPreference("browser.helperApps.neverAsk.saveToDisk",
            "application/pdf," + "text/plain," + "application/octet-stream," + "application/x-pdf,"
                    + "application/vnd.pdf," + "application/vnd.openxmlformats-officedocument.spreadsheethtml,"
                    + "text/csv," + "text/html," + "application/x-msexcel," + "application/excel,"
                    + "application/x-excel," + "application/vnd.ms-excel");
    options.addPreference("pdfjs.disabled", true);

when inspecting the code he finds the profile

new FirefoxProfile(
                new File("/home/henrique/.mozilla/firefox/r6eis7qo.automacao"));

and in firefox when switching between profiles and check the settings are correct

I asked this question on stackoverflow.with, she ended up being marked as duplicate, but the answers aren’t working for me. I’m using Selenium 3.141.59, Firefox 70.0 and geckodriver v0.24.0

  • If the profile generated by Geckodriver or Chromedriver is another then it makes no sense to take the existing uuid, because the profile is different from the one you use default on your OS user, you would have to install the add-on when starting the Driver using options.add_extension() or you can create a separate profile and load as something like this FirefoxProfile('/caminho/pasta/.mozilla/firefox/pastadoperfil') and will have access to an already configured profile that you can adjust and leave it all as you wish.

  • thanks for the reply, and how do I set up a profile? had already searched the web for it, but without success.

  • 2

    I’m running out of time now and using the comment field is tricky, but the night vote to reopen your question and answer in the appropriate field for answers how to do step by step.

1 answer

0


I was able to solve it this way

  FirefoxOptions options = new FirefoxOptions();
    options.addPreference("browser.download.folderList", 2);
    options.addPreference("browser.download.dir", paramDownload);
    options.addPreference("browser.download.useDownloadDir", true);
    options.addPreference("browser.helperApps.neverAsk.saveToDisk",
            "application/pdf," + "text/plain," + "application/octet-stream," + "application/x-pdf,"
                    + "application/vnd.pdf," + "application/vnd.openxmlformats-officedocument.spreadsheethtml,"
                    + "text/csv," + "text/html," + "application/x-msexcel," + "application/excel,"
                    + "application/x-excel," + "application/vnd.ms-excel");

    options.addPreference("pdfjs.disabled", true);
    if (headless) {
        options.addArguments("--headless");
    }
    FirefoxProfile firefoxProfile = new FirefoxProfile();
    firefoxProfile.addExtension(new File("/home/henrique/Documentos/[email protected]"));
    options.setProfile(firefoxProfile);

    System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/home/files/logsGeckodriver.txt");
    WebDriver driver = new FirefoxDriver(options);

to get . xpi from the extension, I installed the extension in a profile, and then I took . xpi inside the profile folder

i tmb realized that in the way quoted in the question, in a way it was working, however it takes about unbelievable 20m to instantiate, the webDriver, it took so long to render the browser that thought it was not working and killed the application.

in the manner quoted in the answer, it takes (about 1m) to render only the first time to startar the server, then works normally

Browser other questions tagged

You are not signed in. Login or sign up in order to post.