-1

I think the Title says it all. I am finding a way to send Command C and Command V using selenium in Python. What I want is that it opens a page, presses Command L and then Command C to copy, and then Command V to paste it somewhere else, but I couldn't find it anyway! Can anyone help?

I tried using the ActionChains, driver.sendKeys method but nothing seem to work, so I came here in the hope to search for an answer. Let's see what happens!

  • I would have suggested using autohotkey, but you are on mac. There might be an alternative. If you find one, this SO answer might be of help: https://stackoverflow.com/questions/41268860/how-to-send-keyboard-shortcut-shift-control-c-in-selenium – DapperDuck Jan 28 '21 at 14:20

2 Answers2

1

You can use ActionChains

from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys

actions = ActionChains(driver)
actions.key_down(Keys.COMMAND).send_keys('C').key_up(Keys. COMMAND).perform()

This will send Command+C

Rahul K
  • 665
  • 10
  • 25
0

import keys frist

from selenium.webdriver.common.keys import Keys

Then use any of :

element.send_keys(Keys.COMMAND+"a") 
element.send_keys(Keys.COMMAND,"a") 

Both works you don't have to use action class

PDHide
  • 18,113
  • 2
  • 31
  • 46