英文:
Allow/enable Clipboard Permission Popup using selenium with JavaScript
问题
如何在使用Selenium Web驱动程序和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?
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'。
在我们的测试代码中的示例:
英文:
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:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论