zoukankan      html  css  js  c++  java
  • web自动化实现自动点击,当cookie失效再次循环点击

    # -*- 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()
  • 相关阅读:
    淘宝网-六属性
    软件架构之黑板模式
    06需求工程-软件建模与分析阅读笔记之六
    05需求工程-软件建模与分析阅读笔记之五
    04需求工程-软件建模与分析阅读笔记之四
    03需求工程-软件建模与分析阅读笔记之三
    第二次冲刺团队绩效评估
    第二次冲刺站立会议07
    第二次冲刺站立会议06
    第二次冲刺站立会议05
  • 原文地址:https://www.cnblogs.com/anhao-world/p/14949246.html
Copyright © 2011-2022 走看看