python selenium send_keys CONTROL,'c'不复制实际文本

mil*_*lls 4 python selenium screen-scraping

我成功地突出显示了网页中的部分,但是 send_keys,.send_keys(Keys.CONTROL, "c")没有将要复制的预期文本放入剪贴板,只有我手动复制的最后一件事是在剪贴板中:

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**
Run Code Online (Sandbox Code Playgroud)

然后我尝试使用 Firefox 编辑菜单来选择所有并复制文本,但也没有工作,并且除了可能提到的错误之外找不到任何在线帮助(尝试过旧版本的 Firefox,但没有解决问题)。有任何想法吗?

小智 5

尝试使用以下代码:

包括下面的标题以导入 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)
Run Code Online (Sandbox Code Playgroud)