Reputation: 225
I have to verify some ads displayed on google search. These ads displayed only when I install the extensions for chrome browser. But when I launch chrome browser from WebDriver script it launches the browser without extentions (even though extensions are already installed) to chrome browser.
I have googled but didnt get much information.
I have tried below method but it didnt work out:
DesiredCapabilities capability = DesiredCapabilities.chrome();
System.setProperty("webdriver.chrome.driver", "libs\\chromedriver.exe");
capability.setCapability("chrome.switches", Arrays.asList("--load-extension=C:\\Users\\ashfaq.md\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Extensions"));
Please help me to resolve this issue.
Upvotes: 2
Views: 4232
Reputation: 1127
You can learn how to install Chrome Extensions via ChromeDriver here:
https://sites.google.com/a/chromium.org/chromedriver/extensions
Upvotes: 1
Reputation: 10079
Though not tested on own end... Please check the following:
ChromeOptions options = new ChromeOptions()
options.addExtensions(new File("/path/to/extension.crx"))
options.setBinary(new File("/path/to/chrome"));
// For use with ChromeDriver:
ChromeDriver driver = new ChromeDriver(options);
// or alternatively:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
// For use with RemoteWebDriver:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
RemoteWebDriver driver = new RemoteWebDriver(
new URL("http://localhost:4444/wd/hub"), capabilities);
Upvotes: 0