I need to use pyperclip on heroku on a selenium app to copy something to clipboard but as the platform runs a 'headless' browser and has no GUI, a clipboard is obscure. is it possible for me to make this work somehow?
Asked
Active
Viewed 105 times
0
-
1I don't know about pyperclip, but for me, copying stuff from a headless browser does not present any real issues when using selenium – C. Peck May 30 '21 at 20:15
-
do you really need clipboard? Can't you save in file and later read from file? maybe better describe why you need clipboard - maybe someone find method to do this without clipboard. – furas May 30 '21 at 22:05
-
@C.Peck how do you do it sir? i only know to copy with pyperclip – Manbust May 31 '21 at 04:40
-
@furas yeah its because i need to send_keys() a large body of text and sending it as a string takes too long. also i tried executescript but my the text box is weird. its the code text box on diffchecker.com and i don't know how to access its value attribute. seems like it is sectioned out line by line edit: send_keys (string) takes too long so i want to use send_keys(Keys.CONTROL, 'v') – Manbust May 31 '21 at 04:43
-
you should write it in question at start - it better explain problem. – furas May 31 '21 at 04:50
1 Answers
0
Selenium can press ctrl + c to copy.
To copy using python and Selenium, you can use the following code:
from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(driver)
actions.key_down(Keys.CONTROL)
actions.send_keys("c")
actions.key_up(Keys.CONTROL)
actions.perform()

C. Peck
- 3,641
- 3
- 19
- 36
-
i think this will work if i upload my files somewhere to scrape from. i need to copy a string already present in my code to clipboard and then paste into diffchecker.com. thank u – Manbust May 31 '21 at 22:02