程序笔记   发布时间:2022-07-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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()

 

大佬总结

以上是大佬教程为你收集整理的web自动化实现自动点击,当cookie失效再次循环点击全部内容,希望文章能够帮你解决web自动化实现自动点击,当cookie失效再次循环点击所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。