Python+selenium+webdriver之鼠标、键盘操作

 鼠标操作

引入action_chains类
from selenium.webdriver.common.action_chains import ActionChains

获取元素
element=driver.find_element_by_id("123")

双击操作
ActionChains(driver).double_click(element).perform()

右击操作
ActionChains(driver).context_click(element).perform()


鼠标悬停
mouse=driver.find_element_by_id("123")
ActionChains(driver).move_to_element(mouse).perform()

键盘操作

引入keys类
from selenium.webdriver.common.keys import Keys

操作复制、粘贴、剪切
driver.find_element_by_id("123").send_keys(Keys.CONTROL,'a')
driver.find_element_by_id("123").send_keys(Keys.CONTROL,'c')
driver.find_element_by_id("123").send_keys(Keys.CONTROL,'x')
driver.find_element_by_id("123").send_keys(Keys.CONTROL,'V')

 

你可能感兴趣的:(Python+selenium+webdriver之鼠标、键盘操作)