selenium Python自动化测试(基本的鼠标事件)

来源:互联网 发布:海口Java招聘 编辑:程序博客网 时间:2024/06/07 18:32
#coding=utf-8
'''
Created on 2015-5-8


@author: user
简单的鼠标事件以及使用方法!!!
context_click() 右击
double_click() 双击
drag_and_drop() 拖动
move_to_element() 鼠标悬停
'''
'''
from selenium import webdriver
#引入ActionChains类
from selenium.webdriver.common.action_chains import ActionChains
#使用方法
brower = webdriver.Firefox()
brower.get("http://www.baidu.com")
#定位到需要右击的元素并赋值给rigth_click
right_click = brower.find_element_by_id("xx")
#对定位到的元素进行右击操作。
ActionChains(brower).context_click(right_click).perform()
'''
#以下是代码解释:
'''
from selenium.webdriver import ActionChains
对于 ActionChains 类下面的方法,在使用之前需要先将模块导入。
ActionChains(driver)
调用 ActionChains()方法,在使用将浏览器驱动 driver 作为参数传入。
context_click(right_click)
context_click()方法用于模拟鼠标右键事件,在调用时需要传入右键的元素。
perform()
执行所有 ActionChains 中存储的行为,可以理解成是对整个操作事件的提交动作。
'''
#鼠标悬停
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
brower = webdriver.Firefox()
brower.get("http://www.baidu.com")
#brower.maximize_window()


move_mouse = brower.find_element_by_xpath(".//*[@id='u1']/a[8]")
ActionChains(brower).move_to_element(move_mouse).perform()
brower.find_element_by_name("tj_nuomi").click()


'''
除此之外,另外几个的用法是一样的。


'''





















































0 0
原创粉丝点击