3

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.

Cleyson Shingu
  • 203
  • 1
  • 3
  • 9

1 Answers1

2

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

Cleyson Shingu
  • 203
  • 1
  • 3
  • 9
  • 1
    Did u solve it? `id_element.send_keys(Keys.CONTROL, 'v')` doesn't work in Ubuntu 16.04, headless Chrome : ( – user3595632 Nov 18 '18 at 06:58
  • Hey, sorry for the late reply. I solved it by not using headless mode while using the clipboard. From what I am concerned for using the clipboard you actually need to have your text on the screen otherwise nothing will be copied. – Cleyson Shingu Jan 04 '19 at 08:17
  • 1
    I'm having the same problem using ubuntu. I guess it's not a windows bug since it also occur on ubuntu! – basilisk Jun 04 '20 at 16:07