标签:全选 http 百度贴吧 path 内容 百度 import key _id
键盘操作需要使用send_keys()进行输入
driver.find_element_by_id(元素id).send_keys(输入的内容,Keys.ENTER)
如下:
send_keys(Keys.ENTER) Enter键
send_keys(Keys.CANCEL,‘a‘) CANCEL+A 全选
send_keys(Keys.CANCEL,‘c‘) CANCEL+C 复制
send_keys(Keys.CANCEL,‘x‘) CANCEL+X 剪切
send_keys(Keys.CANCEL,‘v‘) CANCEL+V 粘贴
send_keys(Keys.F5) 刷新
send_keys(Keys.BACKSPACE) 删除
send_keys(Keys.TAB) Tab键
send_keys(Keys.SPACE) 空格键
send_keys(Keys.ESCAPE) 回退键
代码实现:
1 from selenium import webdriver 2 from selenium.webdriver.common.keys import Keys 3 from selenium.webdriver.support.wait import WebDriverWait 4 from selenium.webdriver.support import expected_conditions as EC 5 from selenium.webdriver.common.by import By 6 driver=webdriver.Chrome() 7 driver.maximize_window() 8 driver.get(‘https://wwww.baidu.com‘) 9 driver.find_element_by_id(‘kw‘).send_keys("柠檬班",Keys.ENTER) 10 WebDriverWait(driver,30).until(EC.visibility_of_element_located((By.XPATH,‘//a[contains(text(),"吧_百度贴吧")]‘))) 11 driver.find_element_by_xpath(‘//a[contains(text(),"吧_百度贴吧")]‘).send_keys(Keys.ENTER)
标签:全选 http 百度贴吧 path 内容 百度 import key _id
原文地址:https://www.cnblogs.com/wsk1988/p/12703262.html