当前位置:网站首页>Selenium advanced operations
Selenium advanced operations
2022-07-06 19:43:00 【Cold Lane (* _*)】
No interface mode
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
driver = webdriver.Chrome(options=options)
driver.get('https://www.baidu.com/')
perform js Code , Pull the page to the bottom
driver.execute_script(
'window.scrollTo(0, document.body.scrollHeight)'
)
Simulate keyboard keys
# Enter cold Lane in the search box
dirver.find_element(By.ID, 'kw').send_keys(' deserted alleyways ')
# Enter a space
dirver.find_element(By.ID, 'kw').send_keys(Keys.SPACE)
# ctrl+a Simulate select all
dirver.find_element(By.ID, 'kw').send_keys(Keys.CANCEL,'a')
# ctrl+c Simulate replication
dirver.find_element(By.ID, 'kw').send_keys(Keys.CANCEL,'c')
# ctrl+v Simulate paste
dirver.find_element(By.ID, 'kw').send_keys(Keys.CANCEL,'v')
# Simulated carriage return
dirver.find_element(By.ID, 'kw').send_keys(Keys.ENTER)
Simulation mouse
Import mouse event class
from selenium.webdriver import ActionChains
Instantiate mouse events
ActionChains(dirver)
Specify mouse behavior
move_to_element()
Execute mouse behavior
perform()
Here is an example
I want to click Advanced Search
Import
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
from selenium import webdriver
Open the browser
dirver = webdriver.Chrome()
dirver.get('https://www.baidu.com/')
Find the location of the setting
Advanced search location has also been found
# Move to settings
set_node = dirver.find_element(By.XPATH, '//*[@id="s-usersetting-top"]')
ActionChains(dirver).move_to_element(to_element=set_node).perform()
# Find the advanced search node , And click the
dirver.find_element(By.LINK_TEXT, ' Advanced search ').click()
Run it to see the effect
a !
Switch handle
Use URL type
Open the link on the page and a new window appears , But browser objects dirver Or the object of the previous page , You need to switch to a different window mirroring operation
Application plan dirver.switch_to.window()
Get all current handles first ( list )
Then switch to the specified handle ( utilize )
all_handles = dirver.window_handles
dirver.switch_to.window(all_handles[1]) # 1 Is the second tab
What is the handle ?
Simply put
I click Ice and snow as the medium An appointment to the Winter Olympics after , There is one more label in the label column above , This is the handle .
selenium frame
characteristic
Web pages are nested in web pages , Switch to frame, Then perform other operations
Processing steps
Switch to the... To be processed frame
stay frame Locate and operate page elements in
Returns the currently processed frame It is the upper level page or main page
Common methods
Switch to frame: driver.switch_to.frame(frame Node object )
Return to upper level :driver.switch_to.parent_frame()
Go back to the main page ;driver.switch_to.default_content()
Instructions
The default support id and name Attribute value lookup :switch_to.frame(id|name)
First find frame node :frame_node = driver.find_element_by_
Switch to frame:dirver.switch_to.frame(frame_node)
边栏推荐
- 腾讯T3大牛手把手教你,大厂内部资料
- Reflection and illegalaccessexception exception during application
- 接雨水问题解析
- Swagger2 reports an error illegal DefaultValue null for parameter type integer
- 部门树递归实现
- Classic 100 questions of algorithm interview, the latest career planning of Android programmers
- Vmware虚拟机无法打开内核设备“\\.\Global\vmx86“的解决方法
- 【基础架构】Flink/Flink-CDC的部署和配置(MySQL / ES)
- Alibaba数据源Druid可视化监控配置
- Zero foundation entry polardb-x: build a highly available system and link the big data screen
猜你喜欢
Blue Bridge Cup microbial proliferation C language
学习探索-使用伪元素清除浮动元素造成的高度坍塌
Live broadcast today | the 2022 Hongji ecological partnership conference of "Renji collaboration has come" is ready to go
CPU负载很低,loadavg很高处理方法
Zero foundation entry polardb-x: build a highly available system and link the big data screen
谷粒商城--分布式高级篇P129~P339(完结)
腾讯T2大牛亲自讲解,跳槽薪资翻倍
如何自定义动漫头像?这6个免费精品在线卡通头像生成器,看一眼就怦然心动!
DaGAN论文解读
接雨水问题解析
随机推荐
USB host driver - UVC swap
[play with Linux] [docker] MySQL installation and configuration
保证接口数据安全的10种方案
DaGAN论文解读
理解 YOLOV1 第二篇 预测阶段 非极大值抑制(NMS)
Druid 数据库连接池 详解
It's enough to read this article to analyze the principle in depth
JDBC details
从sparse.csc.csr_matrix生成邻接矩阵
Teach you to learn JS prototype and prototype chain hand in hand, a tutorial that monkeys can understand
转让malloc()该功能后,发生了什么事内核?附malloc()和free()实现源
Cf960g - bandit Blues (type I Stirling number +ogf)
zabbix 代理服务器 与 zabbix-snmp 监控
Recursive implementation of department tree
Low CPU load and high loadavg processing method
反射及在运用过程中出现的IllegalAccessException异常
Mind map + source code + Notes + project, ByteDance + JD +360+ Netease interview question sorting
In simple terms, interview surprise Edition
学习打卡web
接雨水问题解析