Selenium+Python测试键盘操作---全选、复制、剪切、粘贴

'''
键盘操作--将百度搜索的关键字复制到必应中进行搜索
--导入模块from selenium.webdriver.common.keys import Keys
--剪切
--复制
'''
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep

driver=webdriver.Firefox()
driver.get("http://www.baidu.com/")

driver.find_element_by_css_selector("#kw").send_keys("Python")
sleep(4)

#键盘全选操作
driver.find_element_by_css_selector("#kw").send_keys(Keys.CONTROL,'a')
sleep(2)

#键盘复制操作
driver.find_element_by_css_selector("#kw").send_keys(Keys.CONTROL,'c')
sleep(2)

#键盘剪切操作
# driver.find_element_by_css_selector("#kw").send_keys(Keys.CONTROL,'x')
# sleep(2)

driver.get("https://cn.bing.com/")
sleep(4)
driver.find_element_by_css_selector("#sb_form_q").send_keys(Keys.CONTROL,'v')
sleep(4)
driver.find_element_by_css_selector(".b_searchboxSubmit").click()
sleep(4)

driver.quit()

你可能感兴趣的:(Selenium自动化测试)