zoukankan      html  css  js  c++  java
  • Python+Selenium

    鼠标操作类:action_chains模块的ActionChains类

    使用组成:操作 + 执行(perform())

    导入代码

    from selenium.webdriver.common.action_chains import ActionChains

    查看代码常用操作有:

    click(self, on_element=None)
    click_and_hold(self, on_element=None)  #Holds down the left mouse button on an element.
    context_click(self, on_element=None)   #Performs a context-click (right click) on an element.
    double_click(self, on_element=None)   
    drag_and_drop(self, source, target)   #Holds down the left mouse button on the source element, then moves to the target element and releases the mouse button.
    move_to_element(self, to_element)   #Moving the mouse to the middle of an element.
    release(self, on_element=None)   #Releasing a held mouse button on an element.

    perform() #调用这个函数执行鼠标操作

    示例:

    from selenium.webdriver.common.action_chains import ActionChains
    from selenium import webdriver
    from time import sleep
    from selenium.webdriver.common.by import By
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.get("https://www.baidu.com/")
    sleep(1)
    #找到元素
    loc = (By.ID,"s-usersetting-top")
    ele = driver.find_element(*loc)
    #对元素进行鼠标操作
    #实例化ActionChains类
    ac = ActionChains(driver)
    # 把鼠标悬浮在这个元素
    ac.move_to_element(ele)
    # ac.move_to_element(ele).click(ele) #鼠标悬浮并点击。可把两个动作拆开写
    #执行操作。鼠标操作最后要有一个perform(),执行perform()后面还有鼠标操作代码时,需要再调用一次perform()
    ac.perform()
    sleep(3)
    driver.quit()

  • 相关阅读:
    文献阅读方法 & 如何阅读英文文献
    科研方法
    水熊虫
    表达谱(DGE)测序与转录组测序的差别
    单细胞测序
    SGE:qsub/qstat/qdel/qhost 任务投递和监控
    统计分布汇总 | 生物信息学应用 | R代码 | Univariate distribution relationships
    JELLYFISH
    外泌体
    CDS & ORF & 启动子 & 终止子 & 转录因子 & 基因结构 & UTR
  • 原文地址:https://www.cnblogs.com/sue2015/p/14780740.html
Copyright © 2011-2022 走看看