• selenium入门:鼠标、键盘操作


    #鼠标操作

    from selenium import webdriver

    from selenium.webdriver.common.action_chains import ActionChains

    from time import sleep

    driver=webdriver.Firefox()

    driver.get("http://www.***.net")

    driver.maximize_window()

    driver.refresh()

    driver.find_element_by_css_selector("#kw").send_keys("python")

    sleep(5)

    element=driver.find_element_by_css_selector("#kw")

    #双击操作

    ActionChains(driver).double_click(element).perform()

    sleep(3)

    #右击操作

    ActionChains(driver).context_click(element).perform()

    sleep(3)

    #鼠标悬停

    above=driver.find_element_by_css_selector(".pf")

    ActionChains(driver).move_to_element(above).perform

    sleep(3)

    driver.quit()

    #键盘操作

    from  selenium import webdriver

    from selenium.webdriver.common.keys import Keys

    from time import sleep

    driver=webdriver.Firefox()

    driver.get("http://www.baidu.com")

    driver.find_element_by_css_selector("#kw").send_keys("selenium")

    sleep(3)

    #全选

    driver.find_element_by_css_selector("#kw").send_keys(Keys.CONTROL,'a')

    #复制或剪切

    driver.find_element_by_css_selector("#kw").send_keys(Keys.CONTROL,'c')

    #driver.find_element_by_css_selector("#kw").send_keys(Keys.CONTROL,'x')

    sleep(2)

    driver.get("http://www.sogou.com")

    sleep(2)

    #根据class定位

    driver.find_element_by_css_selector(".sec-input").send_keys(Keys.CONTROL,'v')

    sleep(3)

    driver.quit()

  • 相关阅读:
    URL的JavaScript解决之道
    JavaScript中Date对象的几个扩展方法
    taobao open
    Linux操作系统的日志说明
    DG常用运维命令及常见问题解决
    oracle系统视图
    oracle 自动备份、恢复功能
    oracle队列
    spring学习笔记
    sql语句拾遗
  • 原文地址:https://www.cnblogs.com/luckerzhang/p/9355776.html
Copyright © 2020-2023  润新知