Selenium WebDriver- actionchians模拟鼠标悬停操作
生活随笔
收集整理的這篇文章主要介紹了
Selenium WebDriver- actionchians模拟鼠标悬停操作
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#encoding=utf-8
import unittest
import time
from selenium import webdriver
from selenium.webdriver import ActionChainsclass 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 ActionChainsimport 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()
?
轉載于:https://www.cnblogs.com/qingqing-919/p/8709478.html
總結
以上是生活随笔為你收集整理的Selenium WebDriver- actionchians模拟鼠标悬停操作的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: idea创建maven web项目需要注
- 下一篇: 【CSS】一侧定宽,另一侧自适应的布局该