Selenium - Open Chrome with extensions already installed

Asked

Viewed 944 times

0

Guys, I need the Chrome instance opened via Webdriver come with a plugin already installed "Always" that I open.

I found some content, but it doesn’t work here. They can tell if it was because of the Seleniumdriver update?

Follows the code:

import java.io.File;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class Testes {
    @Test
    public void testeNavegador() {
        try {
            WebDriver navegador = null;
            System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.addExtensions(new File("C:\\Office-Editor_v130.54.56.crx"));
            DesiredCapabilities desiredCapabilities = DesiredCapabilities.chrome();
            desiredCapabilities.setCapability(ChromeOptions.CAPABILITY,chromeOptions);
            navegador = new ChromeDriver(desiredCapabilities);
            navegador.get("chrome://extensions/");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

Some solution?

1 answer

-1

Here you find very well explained how to do... https://seleniumjava.com/2016/05/22/start-the-chrome-browser-with-extensions/

The only thing that got a little confused was that it says that after installing the extensions, you should close the browser and when opening through Lenium the extensions should be active...

I found that it is not enabled. What you should do after the whole procedure is to open the browser through Selenium and then install the extensions. And every time you open by Lenium again, the extensions will be there...

I hope to have helped at least the next visitors of this question...

Browser other questions tagged

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