当前位置:网站首页>selenium的web自动化中常用的js-修改元素属性翻页
selenium的web自动化中常用的js-修改元素属性翻页
2022-07-02 06:22:00 【bthtth】
selenium中可以使用driver.execute_script(script,*args)来执行script代码
一 获取元素readonly属性值,并修改为false
# 使用selenium中的方法来定位元素
target = driver.find_element_by_id("id")
# 编写脚本:获取target元素的readonly属性的值,并修改为false
# arguments[index]用来占位,将被 *args中的参数取代
script = 'arguments[0].readonly;arguments[0].readonly'
# 将变量script和target传入execute_script()
driver.execute_script(script,target)
二 滚动屏幕
1 将目标元素滚动到可视区域
# script 提供了scrollIntoView()将目标元素滚动到可视区域
#scrollIntoView()可以传入一个布尔类型的参数.默认为true,表示将目标元素滚动到可视区域的顶部;传入false,将把目标元素滚动到可是区域的底部
# 1定位目标元素
target = driver.find_element_by_id("id")
# 编写脚本
script = 'arguments[0].scrollIntoView()'
# 执行
driver.execute_script(script,target)
2 将网页底部滚动到可是区域.使用场景是:网页未做分页,需要滚动到某一位置时才会自动刷新获取新的内容
# 将网页滚动到底部
driver.execute_script('window.scrollTo(0,document.body.scrollHeight)')
# 将网页滚动到顶部
driver.execute_script('window.scrollTo(document.body.scrollHeight,0)')
边栏推荐
- Distributed transactions: the final consistency scheme of reliable messages
- 20210306转载如何使TextEdit有背景图片
- FE - Eggjs 结合 Typeorm 出现连接不了数据库
- Cglib代理-代码增强测试
- Is there a really free applet?
- New version of dedecms collection and release plug-in tutorial tool
- MySQL的10大经典错误
- When requesting resttemplate, set the request header, request parameters, and request body.
- automation - Jenkins pipline 执行 nodejs 命令时,提示 node: command not found
- Data science [9]: SVD (2)
猜你喜欢
随机推荐
VLAN experiment of switching technology
深入了解JUC并发(一)什么是JUC
【程序员的自我修养]—找工作反思篇二
Ruijie ebgp configuration case
VRRP之监视上行链路
实习生跑路留了一个大坑,搞出2个线上问题,我被坑惨了
Sentinel rules persist to Nacos
Sparse array (nonlinear structure)
栈(线性结构)
记录一次RDS故障排除--RDS容量徒增
LeetCode 90. Subset II
BGP 路由優選規則和通告原則
计算属性普通函数写法 和 set get 写法
Invalid operation: Load into table ‘sources_orderdata‘ failed. Check ‘stl_load_errors‘ system table
Bgp Routing preference Rules and notice Principles
Arduino Wire 库使用
In depth understanding of JUC concurrency (II) concurrency theory
Sentinel 阿里开源流量防护组件
深入学习JVM底层(五):类加载机制
Sentinel规则持久化到Nacos









