This question already has answers here:
How to install extension permanently in geckodriver

(3个答案)


去年关闭。





Chrome驱动程序在添加扩展程序时被卡住/无法启动网址

ChromeBrowser 74.0.3729.131(正式版)(64位)
ChromeDriver 74.0.3729.6
SeleniumDriver selenium-server-standalone-3.141.59

public class ChromeBrowser {

    public static void main(String args[]){

        try{
            //Code working with out extensions
            System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe");
            WebDriver driver = new ChromeDriver();
            driver.get("http://www.google.com");

            //Code failed with extensions
            ChromeOptions options = new ChromeOptions();
            options.addExtensions(new File("./drivers/modheader_2_1_2.crx"));
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability(ChromeOptions.CAPABILITY, options);
            ChromeDriver drivers = new ChromeDriver(capabilities);
            drivers.get("http://www.google.com");
        }
        catch(Exception e){
            System.out.println("Exception caught :: "+e.getMessage());
        }

    }
}

最佳答案

添加扩展是chrome功能,因此您可以对这两行打折

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);



并通过

ChromeDriver drivers = new ChromeDriver(options);



到ChromeDriver

10-01 19:00
查看更多