from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys#使用组合键需要导入Keys模块
from time import sleep,ctime
self.driver = webdriver.Chrome()
self.driver.get("https://www.baidu.com/")
self.driver.maximize_window()
self.driver.find_element(By.ID,'kw').send_keys('seleniumm')
'''删除多余的m'''
self.driver.find_element(By.ID,'kw').send_keys(Keys.BACK_SPACE)
'''清空input框'''
self.driver.find_element(By.ID,'kw').clear()
sleep(2)
'''输入空格+教程'''
self.driver.find_element(By.ID,'kw').send_keys(Keys.SPACE)
self.driver.find_element(By.ID,'kw').send_keys("教程")
sleep(2)
'''Ctrl+a,全选'''
self.driver.find_element(By.ID,'kw').send_keys(Keys.CONTROL,'a')
sleep(2)
'''ctrl+x,剪切'''
self.driver.find_element(By.ID,'kw').send_keys(Keys.CONTROL,'x')
sleep(2)
'''ctrl+v,粘贴'''
self.driver.find_element(By.ID,'kw').send_keys(Keys.CONTROL,'v')
sleep(2)
'''回车,代替单击操作'''
self.driver.find_element(By.ID,'kw').send_keys(Keys.ENTER)
sleep(2)
self.driver.quit()
|