Selenium Python-无头Chrome无法复制到剪贴板 [英] Selenium Python - Headless Chrome not copying to clipboard

查看:295
本文介绍了Selenium Python-无头Chrome无法复制到剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在执行一个脚本来运行Python Selenium并将某些内容复制到剪贴板. 直到我以无头模式运行它之前,它一直运行良好.现在,它不会将文本复制到剪贴板.

I am doing a script to run Python Selenium and copy some content to clipboard. It has been working nice until I ran it in headless mode. Now it does not copy the text to the clipboard.

有人知道如何解决吗?

这是我的配置

options = webdriver.ChromeOptions()
options.add_experimental_option("prefs", {
        "download.default_directory": indir,
        "download.prompt_for_download": False,
        "download.directory_upgrade": True,
        "safebrowsing.enabled": True})

options.add_argument('--headless')
options.add_argument('--disable-gpu')
driver = webdriver.Chrome(chrome_options=options)

我看到了一些有关设置功能的信息,但我的代码无法满足要求,我得到了SyntaxError: invalid syntax.

I saw something about setting the capabilities but I couldn't fit this in my code, I get a SyntaxError: invalid syntax.

推荐答案

回答我自己的问题,因为将来某些人可能遇到相同的问题... 从搜索结果中,我认为这是Windows中的错误,因为我看到有人说在MAC OS无头模式下和从剪贴板复制/粘贴的效果很好.

Answering my own question because some people in the future mught have the same issue... From the results from my searches I think that this is a bug in Windows because I saw someone saying that in MAC OS headless mode and copy/paste from clipboard works fine.

我尝试使用find_by_...('thing here').text,但是在我的情况下,此操作不起作用,这就是为什么我将其复制到剪贴板的原因.

I tried to use find_by_...('thing here').text but in my case this was not working, that's why I was copying it to clipboard.

无论如何,如果这实际上是Windows的错误,我会尝试使用其他浏览器(我需要将其设置为Chrome,因为我正在为该公司开发工具,并且这里的每个人都使用Chrome).

Anyways, if this is actually a bug from Windows I would give a try to other browsers (I need this to be Chrome because I am doing a tool for the company and everybody here uses Chrome).

我没有找到解决方案,我只是剪切了一部分代码,因为复制到剪贴板"部分仅对少数人有用(因此这些人将在没有headless模式的情况下运行).

I did not find a solution, I just cut part of my code out since the copy to clipboard part is only usefull for a few people (so these people are gonna run without the headless mode).

这篇关于Selenium Python-无头Chrome无法复制到剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆