当前位置:网站首页>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)')
边栏推荐
- 一口气说出 6 种实现延时消息的方案
- Codeforces Round #797 (Div. 3) A—E
- Invalid operation: Load into table ‘sources_orderdata‘ failed. Check ‘stl_load_errors‘ system table
- LeetCode 47. Full arrangement II
- AtCoder Beginner Contest 253 F - Operations on a Matrix // 树状数组
- Don't use the new WP collection. Don't use WordPress collection without update
- Mech 3002 explanation
- Redis---1. Data structure characteristics and operation
- Find the highest value of the current element Z-index of the page
- js中正则表达式的使用
猜你喜欢
Sudo right raising
Invalid operation: Load into table ‘sources_orderdata‘ failed. Check ‘stl_load_errors‘ system table
ShardingSphere-JDBC篇
Sentinel Alibaba open source traffic protection component
Hydration failed because the initial UI does not match what was rendered on the server. One of the reasons for the problem
WLAN相关知识点总结
日期时间API详解
找到页面当前元素z-index最高的数值
Data science [9]: SVD (2)
深入学习JVM底层(四):类文件结构
随机推荐
TensorRT的数据格式定义详解
【程序员的自我修养]—找工作反思篇二
BGP报文详细解释
Detailed definition of tensorrt data format
Detailed explanation of BGP message
10 erreurs classiques de MySQL
计算属性普通函数写法 和 set get 写法
Find the highest value of the current element Z-index of the page
Is there a really free applet?
代码技巧——Controller参数注解@RequestParam
LeetCode 78. subset
Redis - cluster data distribution algorithm & hash slot
浅谈三点建议为所有已经毕业和终将毕业的同学
Top 10 classic MySQL errors
Linear DP (split)
AtCoder Beginner Contest 253 F - Operations on a Matrix // 树状数组
LeetCode 77. combination
ctf-web之练习赛
加密压缩文件解密技巧
Redis——大Key问题