当前位置:网站首页>web自动化:8.2 selenium中如何发送js指令
web自动化:8.2 selenium中如何发送js指令
2022-04-22 06:32:00 【花测试】
在上一节 8.1如何在浏览器发送js指令 中我们了解了一些常用的js指令。
这节,继续学习下在selenium中如何发送js指令。
掌握这个固定语法就可以了:
driver.execute_script(js_code) # js_code 换成你需要的js指令
举个例子:清空百度首页的网页内容
from selenium import webdriver
import time
driver = webdriver.Chrome() # 初始化一个谷歌浏览器
driver.maximize_window() # 浏览器窗口最大化
driver.get("http://www.baidu.com") # 打开一个百度网页
time.sleep(10)
js_code = 'document.body.innerText = ""' # 清空网页
driver.execute_script(js_code)
time.sleep(2)
注意事项:
1、一般python代码和js代码之间要等待一段时间,否则可能页面还没加载出来就执行js代码会出错。
2、 time.sleep(10) 不能替换成隐性等待(等元素出现再操作);可以用显性等待(等url是某个值时再执行)
版权声明
本文为[花测试]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_48415452/article/details/120272016
边栏推荐
- 登录界面——渗你千千万万遍
- PLC项目调试七步法
- 实验6 输入输出流
- flask 数据Model迁移报错
- The practical paper of Shiping information and data security compliance testing was selected into the Chinese core journals
- echars动态实现散点图并自定义信息提示框
- 专注数据安全,世平信息上榜中国网络安全行业全景图六大细分领域
- C-10 age issues
- 越权与业务逻辑漏洞
- Training and empowerment | building a professional technical service team
猜你喜欢

Use SSS framework to build a simple dormitory management system

Raspberry Pie: 4.2-inch ink screen

TCP三次握手和四次挥手

utgard连接opcserver报错Caused by: org.jinterop.dcom.common.JIRuntimeException: Access is denied. [0x800

《数据安全法》解读及安全保密技术应用交流会在京成功举办

基于卷积神经网络LeNet-5模型的mnist手写数字识别

杭州市商用密码应用协会领导一行莅临世平信息参观交流

助力2021杭州市网络安全宣传周 | 世平信息精彩活动合集

Continue raspberry pie 4B + OLED: automatically display the IP address after startup

echars动态实现散点图并自定义信息提示框
随机推荐
读取SAE J1939协议数据流
华为手机adb devices连接设备为空
echars实现自定义山西省地图和地图下钻返回
Observer mode -- ApplicationContext
The practical paper of Shiping information and data security compliance testing was selected into the Chinese core journals
行业应用 |从实践中读懂银行的敏感数据安全防护思路
2021-10-08 selenium headless mode open browser
如何保护个人信息安全?@每个人,一定不要错过这份干货分享
[write missed scan from scratch] host discovery -- handwritten a subdomain name digger
Comparison of the differences between ArrayList and LinkedList
网页导入3D模型-obj/mtl文件
MySQL queries the attributes of all fields in the database
Raspberry Pie: simulating iSCSI storage
Elmentui table style customization (row color, background color, content scrolling, de scrolling bar)
Shiping information was listed in the panorama of China's network security market in 2021
Grail layout and double wing layout
Industry application | the way of data security and compliance construction of government big data platform
世平信息董事长王世晞荣获2020年度新锐人物奖
Wangshixi, chairman of Shiping information, won the 2020 new person Award
Configuration list of raspberry pie (entry reference)