The keys () class provides a way to shortcut keys
Frequently used shortcut key operations
Send_keys (keys.backspace) Delete key
Send_keys (keys. Enter) enter
Send.keys (keys.space) space key
Send.keys (Keys.control, ' a ') shortcut key Control+a
Send.keys (Keys.control, ' C ') shortcut key Control+c
#coding =utf-8 from
Selenium import webdriver
#导入Keys () class from
Selenium.webdriver.common.keys import keys
Driver = Webdriver. Firefox ()
driver.get (' https://www.baidu.com ') driver.find_element_by_id (' kw ')
. Send_keys (' Seleniumm ')
#删除多余的一个m
driver.find_element_by_id (' kw '). Send_keys (keys.back_space)
#输入空格键 + tutorial
driver.find_ element_by_id (' kw '). Send_keys (Keys.space) driver.find_element_by_id (' kw ')
. Send_keys (U ' tutorial ')
#全选输入框内容, Use Control+a
driver.find_element_by_id (' kw '). Send_keys (Keys.control, ' A ')
#剪切输入框内容
Driver.find_ element_by_id (' kw '). Send_keys (Keys.control, ' x ')
#粘贴在文本框中
driver.find_element_by_id (' kw '). Send_keys ( Keys.control, ' V ')
#回车搜索
driver.find_element_by_id (' kw '). Send_keys (Keys.enter)
driver.quit ()