用Selenium实现鼠标悬浮

2022-04-28  本文已影响0人  吱吱菌啦啦

示例:将鼠标悬浮到百度的’设置‘按钮上

具体实现步骤如下:

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()
上一篇 下一篇

猜你喜欢

热点阅读