WebDriver键盘操作常用方法_新手入门笔记
导包:from selenium.webdriver.common.keys import Keys2.2常用的键盘操作
1. send_keys ( Keys.BACK_SPACE)
删除键(BackSpace)
2. send_keys (Keys.SPACE)
空格键(Space)
3. send_keys (Keys.TAB)
制表键(Tab)
4. send_keys(Keys.ESCAPE)
回退键(Esc)
5. send_keys (Keys.ENTER)
回车键(Enter)
6. send_keys(Keys.cONTROL , 'a')
全选(Ctr1+A)
7. send_keys(Keys.CONTROL , 'c')
复制(Ctrl+C)
提示:以上方法就不一个一个讲解了,因为调用方法都一样;
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from time import sleep
driver = webdriver.Chrome()
driver.get("https://www.baidu.com")
text = driver.find_element(By.ID,"kw")
text.send_keys("怎么样去死")
sleep(2)
text.send_keys(Keys.BACK_SPACE)
sleep(2)
text.send_keys(Keys.CONTROL,'a')
sleep(2)
页:
[1]