'Accept Clipboard permission request in chrome using selenium
I have want to copy some content and paste it and analyze it.
I have Headless Linux.
When I copy it. I tried to paste it via pyperclip it gave me
not implemented error. Then I tried and installed xclip.
This Gave me error xsel: Can't open display: (null)
So I tried another way. to use a javascript snippet to run it in python to get clipboard data. that's the code
javascript_script = '''
var done = arguments[0];
setTimeout(async () => {
const text = await navigator.clipboard.readText();
console.log(text);
done(text);
}, 3000);
'''
driver.execute_async_script(javascript_script)
That's running good but require to accept allow clipboard. but i cannot find how to enable it.
Need help to resolve with
- xclip or
- allow the clipboard access automatically
Solution 1:[1]
Here is how to allow clipboard in Chrome + Selenium + Node.js:
const {Builder} = require('selenium-webdriver');
const {Options} = require('selenium-webdriver/chrome');
const options = new Options()
options.setUserPreferences({
profile: {
content_settings: {
exceptions: {
clipboard: {
['http://YOURURL,*']:
{
"expiration": "0",
"last_modified": Date.now(),
"model": 0,
"setting": 1
},
}
}
}
}
})
const driver = await new Builder().forBrowser('chrome').setChromeOptions(options).build()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
