首页 > 其他分享 >创建一个滚动到页面底部的循环,然后检查该元素

创建一个滚动到页面底部的循环,然后检查该元素

时间:2023-09-09 16:58:59浏览次数:29  
标签:count 滚动 创建 selenium text import wait channel 页面

from selenium.common.exceptions import NoSuchElementException, TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# create a dedicated wait object to wait for a brief period for the elements to be created.
wait = WebDriverWait(driver, 5)
# (...)
# find channel on SCROLLABLE side menu

# limit the number of scrolls
count = 0
while count < 5:
    driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")
    try:
        channel_text = wait.until(
            EC.presence_of_element_located(
             (By.XPATH, f"//*[contains(text(), 'channel-name')]")
            )
        )
        break
    except TimeoutException:
        pass
    count += 1
else:
    # do whatever must be done if the element is never found.
    pass
print(channel_text)

 

标签:count,滚动,创建,selenium,text,import,wait,channel,页面
From: https://www.cnblogs.com/QQ-77Ly/p/17689711.html

相关文章

  • c++创建简单窗口
    #include<Windows.h>//自定义的窗口过程LRESULTCALLBACKMyWindowProc(HWNDhWnd,UINTMsg,WPARAMwParam,LPARAMlParam){switch(Msg){caseWM_DESTROY://WM_DESTORY代表“窗口关闭”消息PostQuitMessage(0);return0;default......
  • 【js】【统计次数】静态页面访问次数 js页面请求次数统计
    ​效果: 源码:<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>静态页面访问量统计</title></head><body><scripttype="text/javascript">varpgcoun......
  • uniapp 子页面 滚动监听 是否到底
    主要属性:  handleScrollToLower<template><viewclass="menu"><scroll-viewid="scrollContainer"class="scroll"scroll-y@scrolltolower="handleSc......
  • 用来练习sql的库表创建sql文件
    1.创建work.sql文件,填写以下内容--MySQLdump10.13Distrib5.7.43,forLinux(x86_64)----Host:localhostDatabase:work----------------------------------------------------------Serverversion 5.7.43/*!40101SET@OLD_CHARACTER_SET_CLIENT=@@CHARACT......
  • 创建Anaconda虚拟Python环境的方法
      本文介绍在Anaconda环境下,创建、使用与删除Python虚拟环境的方法。  在Python的使用过程中,我们常常由于不同Python版本以及不同第三方库版本的支持情况与相互之间的冲突情况,而需要创建不同的Python虚拟环境;在Anaconda的帮助下,这一步骤就变得十分方便。  首先,我们需要打......
  • VBA*CommandBars控制菜单栏上的菜单(如页面设置、打印)
    Subtest()'视图工具栏中,各种工具对应的英文名称'worksheetmenubar表示工作表菜单栏Application.CommandBars("worksheetmenubar").Enabled=false'formatting表示格式工具栏Application.CommandBars("Formatting").Visible=False'standard表示常用工具栏Appl......
  • Vue源码学习(三):<templete>渲染第二步,创建ast语法树
    好家伙,书接上回 在上一篇Vue源码学习(二):<templete>渲染第一步,模板解析中,我们完成了模板解析现在我们继续,将模板解析的转换为ast语法树 1.前情提要代码已开源https://github.com/Fattiger4399/analytic-vue.git手动调试一遍,胜过我解释给你听一万遍functionstart......
  • jenkins 插件更新页面报错
    jenkins插件更新页面报错:Jenkins安装插件出现Signatureverificationfailedinupdatesite'default'(showdetails)在docker-compose.yml启动文件加上hudson.model.DownloadService.noSignatureCheck=true环境变量version:"3.6"services:competent_goodall:......
  • Java对象创建过程,类的生命周期,Java的对象结构
    一、Java对象创建过程1、JVM遇到一条新建对象的指令时,首先去检查这个指令的参数是否能在常量池中定义到一个类的符号引用,然后加载这个类;2、为对象分配内存。一种办法时“指针碰撞”,一种办法是“空闲列表”,最终常用的办法是“本地线程缓冲分配”;3、将除对象头外的对象内存空间初始化......
  • WPF 获取页面的子级
    usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Windows;usingSystem.Windows.Media; namespaceK.Controls.Controls.Helper{publicclassGetChildHelper{publicstaticTGetVisualCh......