How to programmatically configure Chrome extension through Selenium WebDriver How to programmatically configure Chrome extension through Selenium WebDriver selenium selenium

How to programmatically configure Chrome extension through Selenium WebDriver


Since you mention that the problem is mainly on remote and I notice you are using SauceLabs, have you check this article from them?

https://support.saucelabs.com/customer/en/portal/articles/2200902-creating-custom-firefox-profiles-and-chrome-instances-for-your-automated-testing

Installing an Firefox Extension such as Modify Headers(You would need download the .xpi file on your machine first):DesiredCapabilities caps = new DesiredCapabilities();FirefoxProfile profile = new FirefoxProfile();profile.addExtension(new File("path\of\Modify Headers xpi file"));profile.setPreference("general.useragent.override", "UA-STRING");profile.setPreference("extensions.modify_headers.currentVersion", "0.7.1.1-signed");profile.setPreference("modifyheaders.headers.count", 1);profile.setPreference("modifyheaders.headers.action0", "Add");profile.setPreference("modifyheaders.headers.name0", "X-Forwarded-For");profile.setPreference("modifyheaders.headers.value0", "161.76.79.1");profile.setPreference("modifyheaders.headers.enabled0", true);profile.setPreference("modifyheaders.config.active", true);profile.setPreference("modifyheaders.config.alwaysOn", true);profile.setPreference("modifyheaders.config.start", true);caps.setCapability(FirefoxDriver.PROFILE, profile);NOTE: If you trying to do the same using C#, you would need to use the ToBase64String() method.


    public void AddHeaderChrome()    {    ChromeOptions  options = new ChromeOptions();    options.addExtensions(new File("C:\\Downloads\\ModHeader_v2.0.9.crx"));     DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();    capabilities.setCapability(CapabilityType.options);    // launch the browser    WebDriver driver = new ChromeDriver(options);    String HeadersName[]=new String[10];    String HeadersValue[]=new String[10];;    int length;    if(ConfigDetails.HeadersName.contains(","))    {    HeadersName=ConfigDetails.HeadersName.split(",");    HeadersValue=ConfigDetails.HeadersValue.split(",");    length=HeadersName.length;    }    else    {       HeadersName[0]=ConfigDetails.HeadersName;        HeadersValue[0]=ConfigDetails.HeadersValue;       length=1;    }       int field_no=1;    for(int i=0;i<length;i++)    {    driver.get("chrome-extension://idgpnmonknjnojddfkpgkljpfnnfcklj/popup.html");    driver.findElement(By.xpath("//input[@id='fl-input-"+field_no+"']")).sendKeys(HeadersName[i]);    driver.findElement(By.xpath("//input[@id='fl-input-"+(field_no+1)+"']")).sendKeys(HeadersValue[i]);    field_no+=2    }


An extension on Chrome has a constant unique ID.

You can use selenium web driver navigate to chrome-extension://<EXTENSION_UUIF>/options.html, here options.html is the preference page you defined.

Then execute a snippet of script to change the settings that stored in chrome.storage.local.