selenium解决页面一直刷新,无法获取元素的问题

  1. 这里的场景是页面一直在刷新,脚本处于等待中没有继续往下执行。
  2. 百度之后,chrome之类的浏览器可以按esc停止刷新。
  3. 适时手动按esc键盘,脚本往下继续执行。
  4. 综上,启动了两个线程,一个线程执行_send_esc方法;另一个线程执行原始的tcpdump_go_stop方法。
  5. 注意,页面要保持在前端展示

不关注返回值:

复制代码
def test_TCPdump():
    '''
    1、点击GO,等几秒钟,再点击stop
    2、检索界面是否有文件可以被下载,其大小、时间是否符合预期
    '''
    driver = gen_chrome_driver()
    # 登录
    netone_login(driver)

    click_network_tools(driver)
    click_TCPdump_tab(driver)

    # tcpdump_go_stop(driver)
    thread1 = threading.Thread(target=tcpdump_go_stop, args=(driver,))
    thread2 = threading.Thread(target=_send_esc)
    # 启动线程
    thread1.start()
    thread2.start()
    # 等待线程执行完毕
    thread1.join()
    thread2.join()

    driver.quit()


def _send_esc():
    time.sleep(3)
    pyautogui.press('esc')
复制代码

 关注返回值

复制代码
def test_TCPdump():
    '''
    1、点击GO,等几秒钟,再点击stop
    2、检索界面是否有文件可以被下载,其大小、时间是否符合预期
    '''
    driver = gen_chrome_driver()
    # 登录
    netone_login(driver)

    time.sleep(1)
    click_network_tools(driver)
    click_TCPdump_tab(driver)

    # tcpdump_go_stop(driver)

    with concurrent.futures.ThreadPoolExecutor() as executor:
        # 提交任务到线程池,并获取Future对象
        future1 = executor.submit(tcpdump_go_stop, driver)
        future2 = executor.submit(_send_esc)

        # 等待任务执行完成并获取返回值
        result = future1.result()
    if not result:
        assert False
    
    # thread1 = threading.Thread(target=tcpdump_go_stop, args=(driver,))
    # thread2 = threading.Thread(target=_send_esc)
    # # 启动线程
    # thread1.start()
    # thread2.start()
    # # 等待线程执行完毕
    # thread1.join()
    # thread2.join()
    
    driver.quit()


def _send_esc():
    time.sleep(3)
    pyautogui.press('esc')
复制代码

 

posted @   你说夕阳很美  阅读(587)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示