英文:
Get value of clipboard from a Selenium Grid via Python
问题
我正在使用Selenium for Python连接到我的网格并控制浏览器。
不,我正在尝试获取我的浏览器在网格上的剪贴板数据并将其复制到我的Python代码中。
我尝试过使用from tkinter import Tk
和clipboard = Tk().clipboard_get()
,但显然它复制的是我的主机剪贴板,而不是Selenium网格上的剪贴板。
有办法访问它吗?
英文:
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?
答案1
得分: 1
我认为您可以使用JavaScript通过驱动程序复制:
```python
clipboard_data = driver.execute_script("return await navigator.clipboard.readText();"))
您还需要为您所在的站点授予使用剪贴板的权限,因此在启动驱动程序时,您需要添加以下选项:
options.add_experimental_option("prefs", {"profile.content_settings.exceptions.clipboard": {"[*.]httpbin.org,*": {'last_modified': (time.time()*1000), 'setting': 1}}})
将httpbin替换为您的站点(您还可以使用localhost)。
<details>
<summary>英文:</summary>
I think you can use javascript to copy using the driver:
```python
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).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论