Python selenium press ctrl + v at the same time

Viewed 2211

I'm trying to press Ctrl + V at the same time on selenium chromedriver, I tried a lot of different combinations, like element.send_keys(Keys.CONTROL, 'V') or very similar things. Nothing worked. I'm working on WIndows 10

3 Answers

According to the docs of the Selenium (The Docs), This is the solution for Control+C:

ActionChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform()

You can just exchange the 'c' key by 'v' and it should work
you can possibly add the element you trying it to insert into by changing keys.CONTROL to keys.CONTROL, element

use small letter v:

both answers will work:

element.send_keys(Keys.CONTROL, 'v')

element.send_keys(Keys.CONTROL + 'v')

Eg:

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

driver = webdriver.Chrome(executable_path="C:\\Users\\prave\\Downloads\\travelBA\\chromedriver.exe")
driver.get("http://www.python.org")
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
time.sleep(3)
elem.send_keys(Keys.CONTROL + "a")
time.sleep(3)
elem.send_keys(Keys.CONTROL + "c")
time.sleep(3)
elem.send_keys("test")
time.sleep(3)

elem.send_keys(Keys.CONTROL + "a")
time.sleep(3)
elem.send_keys(Keys.CONTROL + "v")
time.sleep(3)

Use + instead of ,

element.send_keys(Keys.CONTROL + 'V')
Related