Selenium Python - Headless Chrome not copying to clipboard

半城伤御伤魂 提交于 2019-12-11 07:36:40

问题


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.

Does anyone know how to solve this?

Here it is my configuration

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)

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


回答1:


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.

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.

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).

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).



来源:https://stackoverflow.com/questions/50751960/selenium-python-headless-chrome-not-copying-to-clipboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!