8

I've just upgraded to the latest version of Chrome 87. My Webdriver.io/Selenium tests used to run fine regardless of if the Chrome window was in the foreground or the background. Now, after upgrading, the tests pass if the window is in the foreground, but not if it's in the background.

I'm not minimizing the Chrome window running my tests. I'm just pressing Alt+Tab so that my IDE is in front of Chrome and it's behind.

I know Chrome 87 has a new "feature" where it uses less CPU if it's not in the foreground. Is there a way to turn this off with either Chrome or Chromedriver settings?

It seems that my test is finding the button to click on, but Chrome isn't registering the click.

Ryan Shillington
  • 15,463
  • 10
  • 75
  • 85

5 Answers5

7

This is a bug in Chrome 87:

https://bugs.chromium.org/p/chromedriver/issues/detail?id=3641&sort=-id

Workaround

Node JS

The workaround is to set the "localState" in Webdriver.io's desiredCapabilities like the below in Node.JS/Chimpy:

chimpOptions.webdriverio.desiredCapabilities = {
  chromeOptions: {
    args: ["--no-sandbox", ...],
    prefs: {...}
    },
    localState: {
      "browser.enabled_labs_experiments": ["calculate-native-win-occlusion@2"],
    },
  },
  ...
};

Java

ChromeOptions options = new ChromeOptions();
   
HashMap<String, Object> chromeLocalStatePrefs = new HashMap<String, Object>();
List<String> experimentalFlags = new ArrayList<String>();
experimentalFlags.add("calculate-native-win-occlusion@2");
chromeLocalStatePrefs.put("browser.enabled_labs_experiments", experimentalFlags);
options.setExperimentalOption("localState", chromeLocalStatePrefs);

Previous Answer

The other workaround is to leave a small lip of the background Chrome window underneath your active browser/IDE/etc.

In the image below, you can see a small amount of the Chrome window running the test.

enter image description here

Ryan Shillington
  • 15,463
  • 10
  • 75
  • 85
4

the latest chrome - chromedriver has resolved this issue enter image description here

mo-ta-to
  • 188
  • 2
  • 11
3

I am using C# and facing same issue. I have added a workaround by adding minimize and maximize window like below. Usually we assert page title, hence the switching to window is bringing the focus and other test actions are passing. below one is the workaround for taking screenshot failure.

private void MinMaxWindow(ChromeDriver driver)
{
        driver.Manage().Window.Minimize();
        driver.Manage().Window.Maximize();
}

Edit, Dev has given workaround like below.

Java

 ChromeOptions options = new ChromeOptions();   
    HashMap<String, Object> chromeLocalStatePrefs = new HashMap<String, Object>();
    List<String> experimentalFlags = new ArrayList<String>();
    experimentalFlags.add("calculate-native-win-occlusion@2");
    chromeLocalStatePrefs.put("browser.enabled_labs_experiments", experimentalFlags);
    options.setExperimentalOption("localState", chromeLocalStatePrefs);

Python

chrome_options = webdriver.ChromeOptions()
    experimentalFlags = ['calculate-native-win-occlusion@2']
    chromeLocalStatePrefs = { 'browser.enabled_labs_experiments' : experimentalFlags}
    chrome_options.add_experimental_option('localState',chromeLocalStatePrefs);
parth
  • 51
  • 6
  • I got replay from dev in https://bugs.chromium.org/p/chromedriver/issues/detail?id=3657#c12 ChromeOptions options = new ChromeOptions(); options.AddLocalStatePreference("browser", new { enabled_labs_experiments = new string[] { "calculate-native-win-occlusion@2" } }); – parth Nov 21 '20 at 05:20
  • This is great, but can you please add the C# equivalent? – Mike Johnston Nov 23 '20 at 18:12
  • ChromeOptions options = new ChromeOptions(); options.AddLocalStatePreference("browser", new { enabled_labs_experiments = new string[] { "calculate-native-win-occlusion@2" } }); – parth Dec 08 '20 at 15:09
3

For now, you can use this workaround:

  1. Download the previous version of Chrome. This one is for version 81: https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Win/735601/

  2. Specify a direct path to the chrome.exe executable via parameter "chrome_binary":

java -jar selenium-server-standalone-3.141.59.jar -role node -hub http://192.168.88.42:4444/grid/register -browser browserName=chrome,platform=ANY,maxInstances=60,seleniumProtocol=WebDriver,applicationName=test4,chrome_binary=C:\Users\PC\Downloads\Win_735601_chrome-win\chrome-win\chrome.exe -maxSession 60
  1. Enjoy using an older version of Chrome.
Ryan Shillington
  • 15,463
  • 10
  • 75
  • 85
3

chromeOptions.addArguments("--disable-backgrounding-occluded-windows");

I ran into same issue since updating to Chrome 87 and chrome driver 87.

Found the fix here: https://support.google.com/chrome/thread/83911899?hl=en

Rob G
  • 55
  • 5