当前位置:网站首页>Web automation: 8.1 how to send JS instructions in the browser
Web automation: 8.1 how to send JS instructions in the browser
2022-04-22 08:05:00 【Flower test】
Suggested reading object : No front-end Foundation , Can't Javascript ,web automation (selenium) The small white
web automated testing , why selenium Still need to learn js Instructions ?
The previous sections talked about selenium The operation of , But there are some browser operations ( Such as : Page scrolling 、 Time choice 、 Documents, etc. ) Not directly through selenium Realization . therefore , We also need to know some simple js Instructions , By sending js Instructions let the browser perform the corresponding operation .
js What is it? ?
HTML Only responsible for static display
Javascript The programming language used by front-end Engineers . effect : Give Way web The dynamic effect of web pages .
Almost all browsers have built-in Javascript execution environment , So you can directly in the browser – Developer Tools –Console Write and execute js command .
selenium Schematic diagram

js How to control the browser ?
DOM(Document object model)
document object , Represents the current entire web page . Input document, Will return the code of this web page .
I won't talk about the details here , If you are interested, you can check the information yourself ( I'm also the front-end Xiaobai , I'm afraid that if I don't speak clearly, it will mislead everyone )
practice :
1、 Define a name, And print name
Print Syntax :console.log(name)

2、 Element localization
stay python in find_element(‘id’, ‘kw’) adopt webdriver Turn into js Instructions getElementById(“kw”), So the two effects are the same .
js The instruction can only modify the front-end display , Refresh the page and restore it to its original .
# Locate Baidu input box elements
el = document.getElementById("kw")
# Modify the of this element value value (selenium Only properties can be obtained , Properties cannot be modified )
el.value = ' Flower test '
# The input box is grayed out and cannot be modified
el.disabled = true
# The input box changes back to the inputable state
el.disabled = false
# Empty web page . This method can be updated or modified , Even rewrite the whole html
document.body.innerText = ''
版权声明
本文为[Flower test]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220628391256.html
边栏推荐
- .net WebAPI访问授权机制及流程设计(header token+redis)
- Bert模型系列一:输入到底是什么东西呢?
- 八阿哥纪事【三】
- 【世平信息】刻录内容保密检查与合规管控解决方案
- Web课设----HIS系统
- C # made a simple raspberry pie IP search tool
- .net 5 Web自定义中间件实现返回默认图片
- Login interface - infiltrate you thousands of times
- Continue raspberry pie 4B + OLED: automatically display the IP address after startup
- Technical puzzle | how does PLC execute interrupt? How to apply it?
猜你喜欢

华为手机adb devices连接设备为空
web自动化:5.2selenium鼠标操作原理:ActionChains-延时调用

How to protect personal information security@ Everyone must not miss this dry goods sharing

Ultra vires and business logic vulnerabilities

Bert model series 1: what exactly is input?

Mysql索引的探索

Postman interface automation-3-tests assertion 3: get dynamic parameters and set environment variables (Interface Association)

Software development specification

使用sss 框架搭建简单毕设, 宿舍管理系统

Shiping information was listed in the panorama of China's network security market in 2021
随机推荐
关于transformer机制的理解
Login interface - infiltrate you thousands of times
postman初级-6-console:打印并查看日志
Continue raspberry pie 4B + OLED: automatically display the IP address after startup
世平信息参与衡阳市“船山论坛”企业路演,畅谈数据安全,助力协同创新
Shiping information has successfully passed the evaluation of "capability verification of data security products" of China Academy of communications and communications
JSON相关
On June 1st, write a poem
Training and empowerment | building a professional technical service team
[technology] how does Siemens soft PLC communicate with configuration software?
web自动化:8.3 selenium中如何实现浏览器的窗口滚动
ik分词器-简单使用
聚焦科技创新 | 世平信息亮相科创中国技术路演——信息技术与安全专场
Flink自定义sink端SinkFunction的应用
【Mock数据】fastmock根据传入参数动态返回mock内容
.net5 WebAPI中搭建WebSocket服务端
node配置环境cmd不生效
使用sss 框架搭建简单毕设, 宿舍管理系统
postman接口自动化-3-Tests断言3:获取动态参数,设置环境变量(接口关联)
Echars realizes customized map of Shanxi Province and map drill down return