我正在尝试使用Chrome,但我需要对用户隐藏它。所以我试图用Chromeoptions使用"无头"
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("C://temp//1.14.12_0.crx"));
options.addArguments("disable-infobars");
options.addArguments("headless");
,但后来我崩溃了以下例外:
[1524948093.974][WARNING]: chrome quit unexpectedly, leaving behind temporary directories for debugging:
[1524948093.974][SEVERE]: Port leaked: 12545
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: failed to wait for extension background page to load: chrome-extension://cjpalhdlnbpafiamejdnhcphjbkeiagm/background.html
from unknown error: page could not be found: chrome-extension://cjpalhdlnbpafiamejdnhcphjbkeiagm/background.html
(Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Windows NT 10.0.16299 x86_6
我进行了一些搜索,发现它可能与我还加载了一个广告阻滞剂扩展名的事实有关,因此我暂时评论了扩展加载,并隐藏了镀铬。但是我仍然需要此扩展名在隐藏Chrome时对我有用。
有解决方案吗?
Chrome版本-66Chrome驱动程序版本-2.37
谢谢!
所以,这是一个技巧:
options.addArguments("load-extension=.//resources//1.14.12_0.crx");
而不是
options.addExtensions(new File(".//resources//1.14.12_0.crx"));
享受!