Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python selenium send_keys CONTROL, 'c' not copying actual text

I successfully highlight the section in a web page, but send_keys, .send_keys(Keys.CONTROL, "c"), does not place the intended text to copy in clipboard, only the last thing I manually copied is in clipboard:

from selenium import webdriver 

from selenium.webdriver.common.keys import Keys 

driver = webdriver.Firefox() 

driver.get("http://www.somesite.com") 

driver.find_element_by_id("some id").send_keys(Keys.CONTROL, "a") #this successfully highlights section I need to copy 

elem.send_keys(Keys.CONTROL, "c") # this does not actually copy text**

I tried then using the Firefox edit menu to select all and copy text, but didn't work either and cant find anything online to assist other than possible mention of a bug (tried old version of Firefox, but didn't solve issue). Any ideas?

like image 584
mills Avatar asked Jun 11 '16 11:06

mills


2 Answers

Try using the code below:

Include the header below to import ActionChains

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)
like image 195
Lalit Gehani Avatar answered Sep 29 '22 19:09

Lalit Gehani


Try this:

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

driver = webdriver.Firefox()
driver.get("http://www.somesite.com")  
driver.find_element_by_id("some id").send_keys(Keys.CONTROL, "a")
driver.find_element_by_id("some id").send_keys(Keys.CONTROL, "c")
like image 33
Jackssn Avatar answered Sep 29 '22 19:09

Jackssn