码迷,mamicode.com
首页 > 其他好文 > 详细

selenium调用键盘

时间:2020-04-26 16:41:49      阅读:43      评论:0      收藏:0      [点我收藏+]

标签:max   tps   send   最大   import   sele   图标   浏览器   key   

键盘

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

driver = webdriver.Chrome(executable_path=‘D:\develop_study\chromedriver\chromedriver‘) # 打开浏览器
driver.maximize_window()    #浏览器最大化
driver.get(‘https://www.yuanrenxue.com‘) # 打开目标网站

#定位右上角搜索图标并点击
try:
    element = WebDriverWait(driver,10).until(
        EC.presence_of_element_located((By.CLASS_NAME,‘search-show‘))
    )
    element.click()
except:
    print(‘not locate serarch-show‘)
    driver.quit()



driver.find_element_by_class_name(‘search-show‘).click()
# 找到输入框
search = driver.find_element_by_class_name("search-input")
# 输入 Python教程
search.send_keys(u‘python教程‘)
search.send_keys(Keys.ENTER)


#time.sleep(30)

element = driver.find_element_by_tag_name(‘body‘)
time.sleep(10)
element.send_keys(Keys.DOWN)
time.sleep(10)
element.send_keys(Keys.DOWN)
time.sleep(5)
driver.quit()

键盘组合键

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time


driver = webdriver.Chrome(executable_path=‘D:\develop_study\chromedriver\chromedriver‘)
driver.maximize_window()
driver.get(‘https://www.yuanrenxue.com‘)
time.sleep(5)
element = driver.find_element_by_tag_name(‘body‘)
element.send_keys(Keys.CONTROL,‘a‘)

element.send_keys(Keys.CONTROL,‘w‘)  #关闭窗口无效。

selenium调用键盘

标签:max   tps   send   最大   import   sele   图标   浏览器   key   

原文地址:https://www.cnblogs.com/chenfei2928/p/12780494.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!