Selenium WebDriver- actionchians模拟鼠标悬停操作
2024-09-02 21:49:18
#encoding=utf-8
import unittest
import time
from selenium import webdriver
from selenium.webdriver import ActionChains class VisitSogouByIE(unittest.TestCase): def setUp(self):
#启动IE浏览器
#self.driver = webdriver.Firefox(executable_path = "e:\\geckodriver")
self.driver = webdriver.Ie(executable_path = "e:\\IEDriverServer") def test_roverOnElement(self):
url = "http://127.0.0.1/test_mouse_hover.html"
# 访问自定义的html网页
self.driver.get(url)
# 找到页面上第一个链接元素
link1 = self.driver.find_element_by_partial_link_text(u"指过来1")
# 找到页面上第二个链接元素
link2 = self.driver.find_element_by_partial_link_text(u"指过来2")
# 找到页面上的p元素
p = self.driver.find_element_by_xpath("//p")
print link1.text, link2.text
# 导入需要的Python包
from selenium.webdriver import ActionChains
import time
# 将鼠标悬浮到第一个链接元素上
ActionChains(self.driver).move_to_element(link1).perform()
time.sleep(2)
# 将鼠标从第一个链接元素移动到p元素上
ActionChains(self.driver).move_to_element(p).perform()
time.sleep(2)
# 将鼠标悬浮到第二个链接元素上
ActionChains(self.driver).move_to_element(link1).perform()
time.sleep(2)
# 将鼠标从第二个链接元素移动到p元素上
ActionChains(self.driver).move_to_element(p).perform()
time.sleep(2) def tearDown(self):
# 退出IE浏览器
self.driver.quit() if __name__ == '__main__':
unittest.main()
最新文章
- WPF实现TextBox水印效果
- jQuery Easy UI 开发笔记
- IOS开发/iphone开发多线程
- linux命令别名的使用
- jquery的$.ajax async使用详解
- IOS上传图片
- Android 仿微信小视频录制
- Nginx的代理和反向代理
- Flask+Mysql搭建网站之安装Mysql
- hdoj分类
- AbstractHandlerMapping解读
- entity framework core在独立类库下执行迁移操作
- Android Multimedia框架总结(四)MediaPlayer中从Java层到C++层类关系及prepare及之后其他过程
- 从零开始学 Web 之 DOM(七)事件冒泡
- java之面向对象的基础知识
- P499 usebrass2
- 使用maven构建一个web项目
- 【leetcode】58-LengthofLastWord
- node.js second day
- 【python学习-4】可复用函数与模块