zoukankan      html  css  js  c++  java
  • selenium的元素定位-鼠标事件

    鼠标事件

    ActionChains 类提供了鼠标操作的常用方法:
    
    perform(): 执行所有 ActionChains 中存储的行为;
    
    context_click(): 右击;
    
    double_click(): 双击;
    
    drag_and_drop(source, target): 拖动;
    
    move_to_element(): 鼠标悬停

    参照百度页面鼠标悬浮定位元素

    from selenium import webdriver
    from selenium.webdriver.common.action_chains import ActionChains
    
    driver = webdriver.Chrome()
    driver.get(url='https://www.baidu.com')
    #最大化
    driver.maximize_window()
    #找到设置按钮
    shezhi = driver.find_element_by_xpath("//div[@id='u1']/a[@class='pf']")
    #鼠标悬浮
    ActionChains(driver).move_to_element(shezhi).perform()
    #定位设置-搜索设置
    # sousuo = driver.find_element_by_xpath("//a[@class='setpref']")
    # ActionChains(driver).move_to_element(sousuo).click().perform()
    """
    ActionChains(driver) 实例化对象
    move_to_element(sousuo) 移动到定位的元素上面
    click()点击的动作
    perform()执行整个操作的最后提交动作
    """
    driver.find_element_by_xpath("//a[@class='setpref']").click() #等同于上面2行
  • 相关阅读:
    释放 Linux 系统预留的硬盘空间(转)
    内存置换空间(swap)之建置(转)
    启动挂载(转)
    硬链接与软链接(转)
    磁盘与目录的容量(转)
    linux网络相关配置文件(转)
    python资源库大全
    pikachu学习记录(二)
    pikachu学习记录(一)
    sqlmap基础用法
  • 原文地址:https://www.cnblogs.com/xinjing-jingxin/p/9299835.html
Copyright © 2011-2022 走看看