美文网首页
用Selenium实现鼠标悬浮

用Selenium实现鼠标悬浮

作者: 吱吱菌啦啦 | 来源:发表于2022-04-28 11:12 被阅读0次

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

  • 用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()

相关文章

网友评论

      本文标题:用Selenium实现鼠标悬浮

      本文链接:https://www.haomeiwen.com/subject/wparyrtx.html