Joe Taylor
Joe Taylor

Reputation: 181

Java - Adding extension to chromedriver selenium

I've started a new project in java using the selenium API, I'm needing to add an extension to the chromedriver the only thing is I'm needing to add an extension such as ad-blocker. Now I've looked at a few things on google and the code I've found gives me an error. Now excuse me if I'm being silly but I've missed out a lot of basics on java and was wondering if anyone could help me out on this here's what I have:

ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("adblock.crx"));
options.setBinary(new File("chromedriver.exe"));

ChromeDriver driver = new ChromeDriver(options);
driver.get("http://www.google.com");

but on the line

options.addExtensions(new File("adblock.crx"));

I am getting the error: The method addExtensions(File[]) in the type ChromeOptions is not applicable for the arguments (File)

Why is it saying this?

I have also tried this but the error is the same:

ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("adblock.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);

Upvotes: 2

Views: 665

Answers (2)

Joe Taylor
Joe Taylor

Reputation: 181

Wow, funny to look back at this noob question... Clearly I was passing File and not a File[]

Upvotes: 0

Saifur
Saifur

Reputation: 16201

It does not know where the file is. Provide the full/relative path of the extension. Such as c:\somtheing\adblock.crx

ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("adblock.crx"));
options.setBinary(new File("c:\somtheing\adblock.crx"));

ChromeDriver driver = new ChromeDriver(options);
driver.get("http://www.google.com");

Upvotes: 0

Related Questions