• 关于selenium自动化之键盘操作


    平常我们会用到很多快捷键,那么selenium如何来模拟快捷键操作呢。下面看看下常用快捷键的操作。首先使用快捷键需要导入以下这个包

    from selenium.webdriver.common.keys import Keys

    然后在通过Keys去调用一些方法,如:

    全选   send_keys(Keys.CONTROL,'a')

    复制   send_keys(Keys.CONTROL,'c')

    粘贴   send_keys(Keys.CONTROL,'v')

    简单demo如下:

    from selenium.webdriver.common.keys import Keys
    from selenium import webdriver
    import time
    
    driver = webdriver.Chrome()
    
    
    driver.maximize_window()
    driver.get('http://106.13w/indeogin')
    
    
    driver.find_element_by_css_selector('#login-email-address').send_keys('admin')
    time.sleep(1)
    # todo 全选
    driver.find_element_by_css_selector('#login-email-address').send_keys(Keys.CONTROL,'a')
    time.sleep(2)
    # TODO 复制
    driver.find_element_by_css_selector('#login-email-address').send_keys(Keys.CONTROL,'c')
    time.sleep(2)
    # todo 粘贴
    driver.find_element_by_css_selector('#login-password').send_keys(Keys.CONTROL,'v')
    
    time.sleep(1)
    driver.quit()

    其他快捷键的操作如图所示:

  • 相关阅读:
    Vim step by step
    Ubuntu解压命令全览
    这样才能使本地Mysql服务允许被外部主机连接(两步)
    [Python] logging.logger
    Python Selenium
    MySQL中char、varchar和text的区别
    Way to MongoDB
    Python误区之strip,lstrip,rstrip
    Android Studio Tips
    Way to tmux
  • 原文地址:https://www.cnblogs.com/xiamaojjie/p/11489119.html
Copyright © 2020-2023  润新知