背景:想要实现一个可后台自动操作浏览器输入指令,下载文件至指定目录的功能
源码:
from selenium import webdriver,common
from selenium.webdriver.common.keys import Keys
xxxls = [['part1','命令1']]
host = [["host1","账号","密码","地址"]]
def lazyClick(driver, element):#简单的封装了一下click方法,页面未加载完成的时候会出现NoSuchElementException或者ElementNotInteractableException错误,捕获错误并重试,默认重试50次,相当于最大等待时长50s
f = False
n = 0
while(not f and n<50):
n = n+1
try:
driver.find_element_by_id(element).click()
f = True
except (common.exceptions.NoSuchElementException, common.exceptions.ElementNotInteractableException):
print('页面未加载完成,等待中。')
time.sleep(1)
f = False
def lazySend(driver, element,