码迷,mamicode.com
首页 > 其他好文 > 详细

ActionChains类鼠标操作的常用方法

时间:2019-05-06 01:07:01      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:rod   hao123   lease   释放   get   max   cti   方法   常用方法   

1.context_click() 鼠标右击

2.double_click() 鼠标双击

3.drag_and_drop() 鼠标拖动

4.move_to_element() 鼠标悬停在一个元素上

5.click_and_hold() 按下鼠标左键在一个元素上,release()释放

1.context_click()鼠标右击

 

1 #-*-coding:utf-8-*-
2 from selenium import webdriver
3 from selenium.webdriver.common.action_chains import ActionChains
4 driver = webdriver.Chrome()
5 driver.maximize_window()
6 driver.get("http://www.baidu.com")
7 element = driver.find_element_by_link_text(hao123)
8 ActionChains(driver).context_click(element).perform()

 

2.double_click()鼠标双击

1 #-*-coding:utf-8-*-
2 from selenium import webdriver
3 from selenium.webdriver.common.action_chains import ActionChains
4 driver = webdriver.Chrome()
5 driver.maximize_window()
6 driver.get("http://www.baidu.com")
7 element = driver.find_element_by_link_text(hao123)
8 ActionChains(driver).double_click(element).perform()

3.drag_and_drop() 鼠标拖动

1 #-*-coding:utf-8-*-
2 from selenium import webdriver
3 from selenium.webdriver.common.action_chains import ActionChains
4 driver = webdriver.Chrome()
5 driver.maximize_window()
6 driver.get("http://www.baidu.com")
7 source = driver.find_element_by_link_text(新闻)
8 target = driver.find_element_by_id(kw)
9 ActionChains(driver).drag_and_drop(source,target).perform()

4.move_element_to()

 1 #-*-coding:utf-8-*-
 2 from selenium import webdriver
 3 from selenium.webdriver.common.action_chains import ActionChains
 4 import time
 5 driver = webdriver.Chrome()
 6 driver.maximize_window()
 7 driver.get("http://www.baidu.com")
 8 more_products = driver.find_element_by_link_text(更多产品)
 9 ActionChains(driver).move_to_element(more_products).perform()
10 driver.find_element_by_link_text(音乐).click()
11 time.sleep(3)
12 driver.quit()

5.click_and_hold()按下鼠标左键在一个元素上,release()释放

 1 #-*-coding:utf-8-*-
 2 from selenium import webdriver
 3 from selenium.webdriver.common.action_chains import ActionChains
 4 import time
 5 driver = webdriver.Chrome()
 6 driver.maximize_window()
 7 driver.get("http://www.baidu.com")
 8 element = driver.find_element_by_link_text(新闻)
 9 ActionChains(driver).click_and_hold(element).perform()
10 ActionChains(driver).release(element).perform()
11 time.sleep(3)
12 driver.quit()

 注:perform():执行所有 ActionChains 中存储的行为

ActionChains类鼠标操作的常用方法

标签:rod   hao123   lease   释放   get   max   cti   方法   常用方法   

原文地址:https://www.cnblogs.com/yaoze2018/p/10817000.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!