zoukankan      html  css  js  c++  java
  • 鼠标及键盘操作

    鼠标操作:1、perform():执行   2、context_click():右击  3、double_click():双击  4、drag_and_drop():拖动   5、move_to_element():鼠标悬停

    from selenium import webdriver
    from selenium.webdriver.common.action_chains import ActionChains
    import time
    
    driver = webdriver.Firefox()
    driver.get("https://www.baidu.com")
    time.sleep(2)
    
    
    #定位到要悬停的元素
    mouse = driver.find_element_by_link_text("设置")
    #悬停操作
    ActionChains(driver).move_to_element(mouse).perform()

    键盘操作:

    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    import time
    
    driver = webdriver.Firefox()
    driver.get("https://www.baidu.com")
    time.sleep(2)
    
    
    driver.find_element_by_id("kw").send_keys("selenium")
    time.sleep(2)
    #backspace键,英文大写
    driver.find_element_by_id("kw").send_keys(Keys.BACKSPACE)
    time.sleep(2)
    
    #清除输入框内容
    driver.find_element_by_id("kw").clear()
    time.sleep(2)
    
    driver.find_element_by_id("kw").send_keys("python")
    time.sleep(2)
    #Ctrl+a
    driver.find_element_by_id("kw").send_keys(Keys.CONTROL,'a')
    time.sleep(2)
    
    driver.quit()
  • 相关阅读:
    超级迷宫我的计划表
    不敢死队
    Let the Balloon Rise
    Hangover
    汉诺塔系列2
    Tri Tiling(递推)
    Tiling(递推,高精度)
    Color Me Less
    I Think I Need a Houseboat(圆计算)
    Kbased Numbers(递推)
  • 原文地址:https://www.cnblogs.com/yijierui/p/13387920.html
Copyright © 2011-2022 走看看