1 # #!/usr/bin/python3 2 # -*- coding: utf-8 -*- 3 # @Time : 2020/7/30 9:07 4 # @Author : Gengwu 5 # @FileName: Keys_Option.py 6 # @Software: PyCharm 7 8 #案例:在百度搜索关键词"selenimu",然后将关键词复制或者剪切到另外一个搜索框中 9 10 from selenium import webdriver 11 from time import sleep 12 from selenium.webdriver.common.keys import Keys 13 14 driver=webdriver.Chrome() 15 driver.maximize_window() 16 17 driver.get('https://www.baidu.com/') 18 driver.find_element_by_css_selector('#kw').send_keys('selenium') 19 20 sleep(3) 21 22 #键盘全选操作,ctrl+A 23 driver.find_element_by_css_selector('#kw').send_keys(Keys.CONTROL,'a') 24 sleep(2) 25 26 #键盘复制或者剪切操作,ctrl+c 27 driver.find_element_by_css_selector('#kw').send_keys(Keys.CONTROL,'c') 28 driver.find_element_by_css_selector('#kw').send_keys(Keys.CONTROL,'x') 29 sleep(2) 30 31 #打开搜狗搜索页面 32 driver.get('https://www.sogou.com/') 33 driver.find_element_by_css_selector('.sec-input').send_keys(Keys.CONTROL,'v') 34 sleep(2) 35 36 driver.quit()
以上如果有问题欢迎随时讨论!