当前位置:网站首页>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 ActionChainsInstantiate 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 webdriverOpen 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)
边栏推荐
- 通俗的讲解,带你入门协程
- MySQL information schema learning (I) -- general table
- 潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe
- Mysql Information Schema 学习(一)--通用表
- ZABBIX proxy server and ZABBIX SNMP monitoring
- Hudi vs Delta vs Iceberg
- DaGAN论文解读
- 冒烟测试怎么做
- 1805. Number of different integers in the string
- LeetCode_ Double pointer_ Medium_ 61. rotating linked list
猜你喜欢

MySQL information Schema Learning (i) - - General table

Teach you to learn JS prototype and prototype chain hand in hand, a tutorial that monkeys can understand

深度剖析原理,看完这一篇就够了

VMware virtual machine cannot open the kernel device "\.\global\vmx86"

Phoenix Architecture 3 - transaction processing

Mysql Information Schema 学习(一)--通用表
In depth analysis, Android interview real problem analysis is popular all over the network

Blue Bridge Cup microbial proliferation C language

腾讯T3手把手教你,真的太香了
时钟轮在 RPC 中的应用
随机推荐
Tensorflow2.0 自定义训练的方式求解函数系数
Tensorflow2.0 self defined training method to solve function coefficients
腾讯Android面试必问,10年Android开发经验
How to access localhost:8000 by mobile phone
MATLAB中deg2rad和rad2deg函数的使用
It's enough to read this article to analyze the principle in depth
Understand yolov1 Part II non maximum suppression (NMS) in prediction stage
Low CPU load and high loadavg processing method
思维导图+源代码+笔记+项目,字节跳动+京东+360+网易面试题整理
Swiftui game source code Encyclopedia of Snake game based on geometryreader and preference
打家劫舍III[后序遍历与回溯+动态规划]
广州首个数据安全峰会将在白云区开幕
Cereals Mall - Distributed Advanced p129~p339 (end)
[translation] Digital insider. Selection process of kubecon + cloudnativecon in Europe in 2022
About image reading and processing, etc
[translation] micro survey of cloud native observation ability. Prometheus leads the trend, but there are still obstacles to understanding the health of the system
js实现力扣71题简化路径
How can my Haskell program or library find its version number- How can my Haskell program or library find its version number?
Documents to be used in IC design process
【翻译】供应链安全项目in-toto移至CNCF孵化器