pavankc
pavankc

Reputation: 51

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

setProperty(testOptions, 'desiredCapabilities/goog:chromeOptions/prefs/profile.content_settings.exceptions.clipboard', { '*':
    { setting: 0 }
});
setProperty(testOptions, 'desiredCapabilities/goog:chromeOptions/prefs/profile.content_settings.exceptions.clipboard', { '*':
    { setting: 1 }
});
setProperty(testOptions, 'desiredCapabilities/goog:chromeOptions/prefs/profile.content_settings.exceptions.clipboard', { '*':
    { setting: 2 }
});

Upvotes: 4

Views: 2896

Answers (1)

titusfortner
titusfortner

Reputation: 4194

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

Upvotes: 2

Related Questions