V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
HuSu
V2EX  ›  Python

(自动化测试工具) Python +selenium 进行自动化,每次点击过后出现阻塞,点击事件的后一行代码也不会运行,重新使用鼠标事件进行操作,按钮被按下,却不弹起,也被阻塞,请问这个是什么原因?这边打开的浏览器是有带自己配置的

  •  
  •   HuSu · Sep 8, 2021 · 1275 views
    This topic created in 1692 days ago, the information mentioned may be changed or developed.
    import subprocess
    import time
    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.common.action_chains import ActionChains
    import os
    import xlrd

    print("""

    _ _ ______ _______ _ ______
    | \ | | ____|__ __|/\ | | | ____|
    | \| | |__ | | / \ _ _| |_ ___ | |__ _ __ __ _ _ __ ___ ___
    | . ` | __| | | / /\ \| | | | __/ _ \| __| '__/ _` | '_ ` _ \ / _ \
    | |\ | | | |/ ____ \ |_| | || (_) | | | | | (_| | | | | | | __/
    |_| \_|_| |_/_/ \_\__,_|\__\___/|_| |_| \__,_|_| |_| |_|\___|



    """)


    #表格文档操作,配置读取
    workfile = xlrd.open_workbook('./操作配置文件.xls')
    sheet = workfile.sheet_by_name('work')
    nrows = sheet.nrows

    #定义 exe 路径
    MetacurrentPath = os.path.abspath('metamask.exe')
    class NFTAutoFrame():
    def __init__(self,dr):
    self.dr = dr
    # 简易型运行接口
    def WorkInsert(self):
    #循环判断操作方式
    for i in range(1, nrows):
    if int(sheet.cell_value(i, 0)) == 1:
    print('开始模拟点击')
    element = sheet.cell_value(i,1)
    print(element)
    findelement = self.dr.find_element_by_xpath(element)
    ActionChains(self.dr).double_click(findelement).perform()
    # self.dr.find_element_by_xpath(element).click()
    print(self.dr.title())
    metaelement = '//*[@id="app-content"]/div/div[3]/div/div[3]/div[3]/footer/button[2]'
    metaTest = '确认'
    time.sleep(2)
    # self.dr.find_element_by_xpath(metaelement).click()
    # self.dr.find_element_by_link_text()
    a = self.dr.switch_to_alert()
    a.accept()
    # except:
    # print('点击元素出错,请检查元素是否存在,如遇加载问题可以合理设置强制等待时间')
    elif int(sheet.cell_value(i, 0)) == 2:
    print('开始模拟输入')
    try:
    self.dr.find_element_by_xpath(sheet.cell_value(i, 1)).send_keys(sheet.cell_value(i, 2))
    except:
    print('输入文本信息出错,请检查元素是否存在')
    elif int(sheet.cell_value(i, 0)) == 3:
    print('开始模拟手动操作小狐狸')
    try:
    os.system(MetacurrentPath)
    except:
    print('模拟小狐狸操作失败')
    elif int(sheet.cell_value(i, 0)) == 4:
    print('进行刷新')
    try:
    self.dr.refresh()
    except:

    self.dr.get(self.dr.current_url)
    elif int(sheet.cell_value(i, 0)) == 5:
    print('进行强制停止',sheet.cell_value(i, 2),'秒')
    time.sleep(int(sheet.cell_value(i, 2)))
    else:
    print('请输入正确的进行方式')

    def CloseDriver(self):
    input('运行完毕,请按任意键推出程序')
    try:
    self.dr.close()
    self.dr.quit()
    print('程序已经关闭')
    except:
    print('程序已经关闭')

    if __name__ == '__main__':
    AutoCount = input('请输入希望循环的次数:')
    input('请在打开浏览器后,最大化浏览器,配置好您的小狐狸,并打开需要测试的地址,按任意键继续')
    try:
    chrome_options = Options()
    chrome_options.add_argument(r'--user-data-dir=D:\seleniumAutoConfig')
    dr = webdriver.Chrome(options=chrome_options)
    input('请配置好您的浏览器小狐狸以及网址,配置好请按任意键继续')
    print('系统将在 5 秒后运行自动化程序,请保持调试浏览器在最前面,程序运行时请不要操作鼠标键盘,可能导致程序运行出错')
    number = 5
    for i in range(5):
    secon = number - i
    print('\r 程序运行倒计时……', secon, end='')
    time.sleep(1)
    for i in range(int(AutoCount)):
    NFTAutoFrame(dr=dr).WorkInsert()
    NFTAutoFrame(dr=dr).CloseDriver()
    except:
    print('浏览器打开错误,请确认是否存在占用配置文件夹的已打开浏览器')
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1137 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 23:07 · PVG 07:07 · LAX 16:07 · JFK 19:07
    ♥ Do have faith in what you're doing.