follow yoyo一般定位到元素后要对它进行输入,点击,双击,清除内容等操作还可能使用模拟键盘操作,如回车,Table键,ctrL+C,Ctrl+V等 # coding:utf-8from selenium import webdriver# 导入键盘模块from selenium.webdriver.common.keys import Keys driver = webdriver.Firefox()driver.get("http://www.hordehome.com")driver.implicitly_wait(10)driver.find_element_by_id("search-button").click()driver.find_element_by_id("search-term").clear()driver.find_element_by_id("search-term").send_keys("python")# driver.find_element_by_id("search-term").submit() # 此方法行不通# 模拟ENTER操作回车按钮driver.find_element_by_id("search-term").send_keys(Keys.ENTER) # 经常用到的键盘操作事件send_keys(Keys.Fn)send_keys(Keys.CONTROL,‘c‘)send_keys(Keys.CONTROL,‘v‘)send_keys(Keys.CONTROL,‘a‘)send_keys(Keys.CONTROL,‘x‘)send_keys(Keys.TAB)
原文地址:https://www.cnblogs.com/shanliguniang/p/10647828.html
时间: 2024-10-28 14:52:10