window.chrome.runtime is undefined for selenium webdriver

Viewed 924

I am using Selenium for testing. I noticed a different behavior starting Chrome manually and starting it with selenium. After a lot of investigation I broke the problem down to JavaScript's window.chrome.runtime which is undefined if started with selenium.

After some research on Google I have found people facing similar issues, but none of their solutions worked for me.

I have tried so far to remove the test-type switch:

ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", Arrays.asList("test-type"));

Are there any other ways I can make it work?

2 Answers

Selenium does not start browser with an existing browser profile, it create a temporary one, every single time. So it does not need to send js to check any installed plugins. To avoid the undefined runtime, use an existing browser profile.

ChromeOptions options = new ChromeOptions();
// edit this path
options.addArguments("user-data-dir=C:\\Users\\pburgr\\AppData\\Local\\Google\\Chrome\\User Data");   
driver = new ChromeDriver(options);
Related