使用Selenium和JavaScript允许/启用剪贴板权限弹窗。

huangapple go评论103阅读模式
英文:

Allow/enable Clipboard Permission Popup using selenium with JavaScript

问题

如何在使用Selenium Web驱动程序和JavaScript进行自动化测试时启用/允许剪贴板权限弹出窗口?

使用Selenium和JavaScript允许/启用剪贴板权限弹窗。

当设置为0和2时,它按预期工作,但当设置为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 }
});
英文:

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

使用Selenium和JavaScript允许/启用剪贴板权限弹窗。

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 }
});

答案1

得分: 1

Chrome有一个特殊的端点,因此Selenium实现了一个单独的方法。在JavaScript中,您可以这样做:

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

选项包括:'prompt'、'granted'和'denied'。

在我们的测试代码中的示例:

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

英文:

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

huangapple
  • 本文由 发表于 2023年4月17日 19:16:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76034562.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定