Performing a copy and paste with Selenium 2

后端 未结 8 1880
广开言路
广开言路 2020-11-30 05:05

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

8条回答
  •  孤城傲影
    2020-11-30 05:31

    Pretty simple actually:

    from selenium.webdriver.common.keys import Keys
    
    elem = find_element_by_name("our_element")
    elem.send_keys("bar")
    elem.send_keys(Keys.CONTROL, 'a') #highlight all in box
    elem.send_keys(Keys.CONTROL, 'c') #copy
    elem.send_keys(Keys.CONTROL, 'v') #paste
    

    I imagine this could probably be extended to other commands as well

提交回复
热议问题