问题
I need to launch a particular chrome extension in my automation. I am currently using Selenium with Java. But I am unable to launch my chrome extension.
回答1:
Basicaly there are two approaches.
1. install desired extension in runtime - https://dev.to/razgandeanu/testing-chrome-extensions-with-selenium-491b
2. manualy install desired extension do existing browser profile and use the existing profile in selenium. Like this:
package packageName;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class WebdriverSetup {
public static String chromedriverPath = "C:\\Users\\pburgr\\Desktop\\selenium-tests\\GCH_driver\\chromedriver.exe";
// my default profile folder
public static String chromeProfilePath = "C:\\Users\\pburgr\\AppData\\Local\\Google\\Chrome\\User Data";
public static WebDriver driver;
public static WebDriver startChromeWithCustomProfile() {
System.setProperty("webdriver.chrome.driver", chromedriverPath);
ChromeOptions options = new ChromeOptions();
// loading Chrome with my existing profile instead of a temporary profile
options.addArguments("user-data-dir=" + chromeProfilePath);
driver = new ChromeDriver(options);
driver.manage().window().maximize();
return driver;
}
public static void shutdownChrome() {
driver.close();
driver.quit();
}
}
来源:https://stackoverflow.com/questions/56169933/how-to-launch-chrome-extension-using-automation-robot-framework-etc