2

How to enable/allow clipboard permission popups in automated tests with Selenium web driver and JavaScript?

screenshot

It works as expected when setting is set to 0 and 2 but not when setting is set to 1

  • Popup is shown as expected in below case
setProperty(testOptions, 'desiredCapabilities/goog:chromeOptions/prefs/profile.content_settings.exceptions.clipboard', { '*':
    { setting: 0 }
});
  • Nothing happens in below case
setProperty(testOptions, 'desiredCapabilities/goog:chromeOptions/prefs/profile.content_settings.exceptions.clipboard', { '*':
    { setting: 1 }
});
  • Popup is blocked as expected
setProperty(testOptions, 'desiredCapabilities/goog:chromeOptions/prefs/profile.content_settings.exceptions.clipboard', { '*':
    { setting: 2 }
});
pavankc
  • 21
  • 2

1 Answers1

0

Chrome has a special endpoint for this, so Selenium implements a separate method. In JS you can do:

  await driver.setPermission('clipboard-read', 'granted')
  await driver.setPermission('clipboard-write', 'granted')

options are: 'prompt', 'granted', and 'denied'

Example in our test code:

https://github.com/SeleniumHQ/selenium/blob/selenium-4.10.0/javascript/node/selenium-webdriver/test/chrome/permission_test.js#L37

titusfortner
  • 4,099
  • 2
  • 15
  • 29