selenium python (三)鼠标事件
2015-12-05 22:51
549 查看
# -*- coding: utf-8 -*-
#鼠标事件
#ActionChains类中包括:
# context_click() 右击;
# double_click() 双击;
# drag_and_drop() 拖动;
# move_to_element()鼠标悬停在一个元素上;
#首先引入ActionChains
from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://www.baidu.com')
#定位到要操作的元素
target_element = driver.find_element_by_id('xx')
#执行ActionChains中存储的行为,需要用perform()
#右击元素
ActionChains(driver).context_click(target_element).perform()
#双击元素
ActionChains(driver).double_click(target_element).perform()
#拖动元素drag_and_drop(source,target)
source = driver.find_element_by_id('xx')
target = driver.find_element_by_id('yy')
ActionChains(driver).drag_and_drop(source,target).perform()
#鼠标悬停在一个元素上
ActionChains(driver).move_to_element(target_element).perform()
#鼠标事件
#ActionChains类中包括:
# context_click() 右击;
# double_click() 双击;
# drag_and_drop() 拖动;
# move_to_element()鼠标悬停在一个元素上;
#首先引入ActionChains
from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://www.baidu.com')
#定位到要操作的元素
target_element = driver.find_element_by_id('xx')
#执行ActionChains中存储的行为,需要用perform()
#右击元素
ActionChains(driver).context_click(target_element).perform()
#双击元素
ActionChains(driver).double_click(target_element).perform()
#拖动元素drag_and_drop(source,target)
source = driver.find_element_by_id('xx')
target = driver.find_element_by_id('yy')
ActionChains(driver).drag_and_drop(source,target).perform()
#鼠标悬停在一个元素上
ActionChains(driver).move_to_element(target_element).perform()
相关文章推荐
- 《python爬虫实战》:爬取图片
- python核心编程-filter重构2
- python核心编程-filter函数重构
- python核心编程-filter函数
- python scikit learn 文本分类
- python核心编程-lambda
- 《python爬虫实战》:爬糗百上的段子
- python核心编程-诊断函数
- python基础教程共60课-第10课变量2
- python基础教程共60课-第9课random
- Python中的类概念理解
- python基础教程共60课-第8课while
- python 中的电子邮箱的操作
- (python)下载喜马拉雅电台的音频
- 5.1.7 timezone对象
- Python将时间为AM的转换为24小时制
- python,random.random()和random.Random()的区别联系
- 实现Python str.split功能的小函数
- python读取图像
- Python爬虫进阶一之爬虫框架Scrapy安装配置