I have a script that is ran in pyvirtualdisplay and I need a value of a variable copied to my clipboard.
The following works (simplified version of my script):
from selenium import webdriver
import clipboard
driver = webdriver.Chrome("/home/name/chromedriver")
driver.get("http://pagewithvariable.com")
variable = find_element_by_name("variable")
clipboard.copy(variable)
The following doesn't work:
from selenium import webdriver
import clipboard
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
driver = webdriver.Chrome("/home/name/chromedriver")
driver.get("http://pagewithvariable.com")
variable = find_element_by_name("variable")
clipboard.copy(variable)
The error I am getting while trying to run clipboard in pyvirtualdisplay is the following:
XIO: fatal IO error 11 (Resource temporarily unavailable) on X server ":1195"
after 11 requests (8 known processed) with 0 events remaining.
Help please :)
Okay, so it turned out that pyvirtualdisplay's clipboard is completely separate and there was no indication of the possibility to use your OS's one while in the virtual display.
Since the clipboard will in most cases be used when the script exits, it works when the display is closed. I used to do it in the following way, which doesn't work:
display.popen.terminate()
When the display is closed with the following, clipboard declared AFTER that point, are working properly:
display.stop()
My question was the only thing coming up on Google on the topic, so I decided someone else might find it useful.