Get value of clipboard from a Selenium Grid via Python

Question:

I’m using Selenium for Python to connect to my Grid and command a browser.
No, I’m trying to get the data of the clipboard of my Browser of the grid and copy them into my Python code.

I’ve tried to use from tkinter import Tk and clipboard = Tk().clipboard_get() but it clearly copy the clipboard on my host and not the one the Selenium Grid

Is there a way to access it?

Asked By: NicoCaldo

||

Answers:

I think you can use javascript to copy using the driver:

clipboard_data = driver.execute_script("return await navigator.clipboard.readText();"))

what you also need to do is give the site that you are on permissions to use the clipboard, so when launching the driver you need to add the following option:

options.add_experimental_option("prefs", {"profile.content_settings.exceptions.clipboard": {"[*.]httpbin.org,*": {'last_modified': (time.time()*1000), 'setting': 1}}})

replace httpbin with your site (you can also use localhost).

Answered By: zaki98