当前位置:网站首页>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)
边栏推荐
- usb host 驱动 - UVC 掉包
- Excel 中VBA脚本的简单应用
- Learning and Exploration - function anti shake
- Live broadcast today | the 2022 Hongji ecological partnership conference of "Renji collaboration has come" is ready to go
- Tencent Android interview must ask, 10 years of Android development experience
- Classic 100 questions of algorithm interview, the latest career planning of Android programmers
- MySQL information Schema Learning (i) - - General table
- Interview assault 63: how to remove duplication in MySQL?
- Hudi vs Delta vs Iceberg
- CPU负载很低,loadavg很高处理方法
猜你喜欢
深入浅出,面试突击版
It's super detailed in history. It's too late for you to read this information if you want to find a job
VMware virtual machine cannot open the kernel device "\.\global\vmx86"
Leetcode 30. Concatenate substrings of all words
力扣101题:对称二叉树
Analysis of rainwater connection
[calculating emotion and thought] floor sweeper, typist, information panic and Oppenheimer
Blue Bridge Cup microbial proliferation C language
Classic 100 questions of algorithm interview, the latest career planning of Android programmers
在解决了 2961 个用户反馈后,我做出了这样的改变...
随机推荐
[玩转Linux] [Docker] MySQL安装和配置
凤凰架构3——事务处理
部门树递归实现
[play with Linux] [docker] MySQL installation and configuration
Understand yolov1 Part II non maximum suppression (NMS) in prediction stage
企业精益管理体系介绍
LeetCode_ Double pointer_ Medium_ 61. rotating linked list
腾讯T2大牛亲自讲解,跳槽薪资翻倍
广州首个数据安全峰会将在白云区开幕
[translation] Digital insider. Selection process of kubecon + cloudnativecon in Europe in 2022
Druid 数据库连接池 详解
CF960G - Bandit Blues(第一类斯特林数+OGF)
LeetCode_ Gray code_ Medium_ 89. Gray code
After solving 2961 user feedback, I made such a change
Live broadcast today | the 2022 Hongji ecological partnership conference of "Renji collaboration has come" is ready to go
Documents to be used in IC design process
IC设计流程中需要使用到的文件
Learning and Exploration - Seamless rotation map
Analysis of rainwater connection
时钟轮在 RPC 中的应用