clickformore5=driver.find_element_by_xpath("//*[@id='filePicker2']/a[2]") time.sleep(1) clickformore5.click()
就是这一段出错了,浏览器隐没后下载不了了
下面是完整代码
from selenium import webdriver import time from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.chrome.options import Options # 从options模块中调用Options类 chrome_options = Options() # 实例化Option对象 chrome_options.add_argument('--headless') # 把Chrome浏览器设置为静默模式 driver = webdriver.Chrome(options=chrome_options) # 设置引擎为Chrome,在后台默默运行 driver.get('https://app.xunjiepdf.com/member/loginaccount') time.sleep(1) clickformore=driver.find_element_by_id("switch_logintype_account") clickformore.click() time.sleep(3) driver.find_element_by_name('tb_memAccount').send_keys("17820575639") driver.find_element_by_name('tb_memPwd').send_keys("hb17040512") time.sleep(0.5) clickformore1=driver.find_element_by_name("btn_formLoginAccount") time.sleep(0.5) clickformore1.click() time.sleep(1) clickformore2=driver.find_element_by_class_name("nav-trigger") time.sleep(0.5) clickformore2.click() time.sleep(0.5) ActionChains(driver).move_to_element(driver.find_element_by_link_text("语音识别")).perform() down_data_click = WebDriverWait(driver, 3).until( EC.element_to_be_clickable((By.XPATH, "//*[@id='hader-nav']/li[6]/a/span")) ) time.sleep(2) clickformore3=driver.find_element_by_link_text("语音转文字") time.sleep(1) clickformore3.click() time.sleep(2) # 定位上传按钮,添加本地文件 driver.find_element_by_class_name("webuploader-element-invisible").send_keys('I:\\pycham\\PyCharm 2020.2.3\\语音识别\\奇巧淫计\\'+str(token)) time.sleep(2) clickformore4=driver.find_element_by_xpath("//*[@id='uploader']/div[2]/div[3]/a/span") time.sleep(1) clickformore4.click() time.sleep(15) clickformore5=driver.find_element_by_xpath("//*[@id='filePicker2']/a[2]") time.sleep(1) clickformore5.click()