Is there any way to perform a copy and paste using Selenium 2 and the Python bindings?
I\'ve highlighted the element I want to copy and then I perform the following
I cannot try this on OSX at the moment, but it definitely works on FF and Ubuntu:
import os
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
with open('test.html', 'w') as fp:
fp.write("""\
""")
driver = webdriver.Firefox()
driver.get('file:///{}/test.html'.format(os.getcwd()))
element1 = driver.find_element_by_name('intext')
element2 = driver.find_element_by_name('outtext')
time.sleep(1)
element1.send_keys(Keys.CONTROL, 'a')
time.sleep(1)
element1.send_keys(Keys.CONTROL, 'c')
time.sleep(1)
element2.send_keys(Keys.CONTROL, 'v')
The sleep() statements are just there to be able to see the steps, they are of course not necessary for the program to function.
The ActionChain send_key just switches to the selected element and does a send_keys on it.