示例:将鼠标悬浮到百度的’设置‘按钮上
-
用action.move_to_element()方法
image.png
具体实现步骤如下:
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
class TestActionChains():
def setup(self):
self.driver = webdriver.Chrome()
# 隐式等待
self.driver.implicitly_wait(5)
self.driver.get("http://www.baidu.com")
def teardown(self):
self.driver.quit()
def test_hover(self):
"""
鼠标悬浮
:return:
"""
element_text = self.driver.find_element(By.XPATH, '//*[@id="s-usersetting-top"]')
action = ActionChains(self.driver)
action.move_to_element(element_text)
action.perform()













网友评论