# -*- coding:utf-8 -*- # author:安好 import requests from selenium import webdriver from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.wait import WebDriverWait import time from selenium.webdriver.common.action_chains import ActionChains #下拉菜单获取隐藏元素 browser = webdriver.Chrome() # browser.set_window_size(800, 800) class Ui(object): def __init__(self): try: browser.get('')#填写URL # time.sleep(1)#强制等待 input_user=WebDriverWait(browser,10,2).until(lambda x:x.find_element_by_id('username'))#显示等待 browser.find_element_by_id('username').send_keys('') # time.sleep(1) input_password=WebDriverWait(browser,10,1).until(lambda x:x.find_element_by_id('password')) browser.find_element_by_id('password').send_keys('') # time.sleep(1) button=WebDriverWait(browser,10,1).until(lambda x:x.find_element_by_id('submitbtn')) print('input_user:',input_user,'input_password:',input_password,'button:',button) browser.find_element_by_id('submitbtn').click() # time.sleep(1) except: print('error') def __del__(self): browser.close() def deduction_fee(self): # time.sleep(2) wait=WebDriverWait(browser,10,1) # 使用匿名函数 wait.until(lambda x:x.find_element_by_xpath('//*[text()="订单异常管理"]')) browser.find_element_by_xpath('//*[text()="订单异常管理"]').click()#文本定义 time.sleep(2) js = 'document.getElementsByClassName("el-menu-item")[36].click()' browser.execute_script(js)#对于隐藏元素使用JS获取点击 time.sleep(2) browser.find_element_by_xpath('//*[@id="app"]/div/div[2]/div[2]/div/div/section/div/div[2]/div[1]/button[1]').click() time.sleep(5) count = 1 while True: try: browser.find_element_by_xpath('//*[@id="app"]/div/div[2]/div[2]/div/div/section/div/div[2]/div[2]/div[1]/div/div[4]/div[2]/table/tbody/tr[1]/td[1]/div').click()#文本定义 time.sleep(0.5) browser.find_element_by_xpath('//*[@id="app"]/div/div[2]/div[2]/div/div/section/div/div[2]/div[1]/button[3]').click() count+=1 time.sleep(5) print(count) if count==5000: print(count) break except Exception as e: print(e) Ui().deduction_fee() Ui().deduction_fee()