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
-
can you show the entire code? because element.send_keys() should work – Timeler Nov 30 '20 at 9:52
-
just use small letter v and your code will work – PDHide Nov 30 '20 at 10:21
-
@PDHide no, it does the same, only writes v instead of paste – Destruktor_11 Nov 30 '20 at 10:24
-
which browser are you using – PDHide Nov 30 '20 at 10:28
-
@PDHide I'm using google chrome with chromedriver – Destruktor_11 Nov 30 '20 at 10:30
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
-
do you mean like
ActionChains(driver).key_down(Keys.CONTROL, element).send_keys('v').key_up(Keys.CONTROL, element).perform()
– Destruktor_11 Nov 30 '20 at 10:23 -
i assume so, im not 100% sure on that exact part, i assume you can delete the element from the second bracket, since releasing is not element specific. instead i would add it to the bracket with ('v') – Timeler Nov 30 '20 at 10:26
-
-
Probably this : from selenium.webdriver.common.action_chains import ActionChains – Timeler Nov 30 '20 at 10:34
-
Thanks, it worked perfectly! Here is how it worked
ActionChains(driver).key_down(Keys.CONTROL, element).send_keys('v').key_up(Keys.CONTROL, element).perform()
– Destruktor_11 Nov 30 '20 at 10:48
Use +
instead of ,
element.send_keys(Keys.CONTROL + 'V')
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)
-
The above example types pycon then copys it and then change text to test and then pastes pycon and replaces test – PDHide Nov 30 '20 at 10:43