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);
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");
哇,回顾这个菜鸟问题很有趣......显然我传递的是 File 而不是 File[]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.