Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow/enable Clipboard Permission Popup using selenium with JavaScript

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 }
});
like image 865
pavankc Avatar asked Oct 15 '25 09:10

pavankc


1 Answers

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

like image 112
titusfortner Avatar answered Oct 16 '25 21:10

titusfortner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!