python+selenium embedded scroll bar

Forwarded from: https://yq.aliyun.com/articles/317413?scm=20140722.184.2.173
1. The page Insert picture description here
looks like this: the source code is as follows:
copy it down, save it with text, change the suffix to .html, open it with a browser

<!DOCTYPE html>
<meta charset="UTF-8"> <!-- for HTML5 -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<html>
<head>
<style type="text/css">

div.scroll
{
     
     
background-color:#afafaf;
width:500px;
height:100px;
overflow:auto;
}
</style>
</head>

<body>
<p>欢迎你</p>
<p>这是一个内嵌的div滚动条</p>
<div id="yoyoketang" name="yoyo" class="scroll">这是一个内嵌div:高考,见证过一代代人的青春时光,承载着万千家庭的期盼与梦想。它是一段难忘的回忆,浸透着汗水,有关理想与现实,勇气和坚持。
人们总说高考是人生的一次重大转折,虽然,一张张考卷早已不是决定个人前途命运的唯一凭证,更不是成才的唯一钥匙,但它依然寄托着莘莘学子不负青春的誓言。
今天,我们讲述的是一组平凡的故事,它映射着每个人心中的那份美好,以及在困境面前守望相助永不言弃的精神。zhegedancihenchanghenchangchangchangchangchanchanchanchangchangchangchancg</div>

</body>
</html>

2. The python code is as follows:

#encoding:utf-8
from selenium import webdriver
import time

driver=webdriver.Chrome()
driver.get('file:///C:/Users/18210/Desktop/demo.html')
time.sleep(2)
# 竖向滚动条操作
js1='var q=document.getElementById("yoyoketang").scrollTop = 10000'
driver.execute_script(js1)
time.sleep(2)
js2='var q=document.getElementById("yoyoketang").scrollTop = 0'
driver.execute_script(js2)
time.sleep(2)
# 横向滚动条操作
js3='var q=document.getElementById("yoyoketang").scrollLeft = 10000'
driver.execute_script(js3)
time.sleep(2)
js4='var q=document.getElementById("yoyoketang").scrollLeft = 0'
driver.execute_script(js4)
time.sleep(2)
# 用classname
js5 = "var q=document.getElementsByClassName('scroll')[0].scrollTop = 10000"
driver.execute_script(js5)
js6 = "var q=document.getElementsByClassName('scroll')[0].scrollLeft = 10000"
driver.execute_script(js6)

3. Parameterization:
I want to slide down one page at a time, but I can’t find this height. I will find a way to optimize later

 for i in range(0,6000,850):
     js5 = "var q=document.getElementsByClassName('ag-body-viewport ag-layout-normal ag-row-animation')[0].scrollTop={}".format(i)
     print("===>",i)
     driver.execute_script(js5)
     time.sleep(2)

4. Determine whether the inline scroll bar slides to the bottom
https://blog.csdn.net/zhaoweiya/article/details/108996126

Guess you like

Origin blog.csdn.net/zhaoweiya/article/details/107162825