当前位置:网站首页>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)
边栏推荐
- 【翻译】供应链安全项目in-toto移至CNCF孵化器
- Mysql Information Schema 学习(一)--通用表
- Reflection and illegalaccessexception exception during application
- 深度剖析原理,看完这一篇就够了
- Learning and Exploration - function anti shake
- 谷粒商城--分布式高级篇P129~P339(完结)
- LeetCode_ Gray code_ Medium_ 89. Gray code
- 腾讯Android面试必问,10年Android开发经验
- Dark horse -- redis
- Analysis of rainwater connection
猜你喜欢

冒烟测试怎么做

谷粒商城--分布式高级篇P129~P339(完结)

IC设计流程中需要使用到的文件

保证接口数据安全的10种方案
![[infrastructure] deployment and configuration of Flink / Flink CDC (MySQL / es)](/img/1e/b270a81c8457f1eae34f55c004a01a.png)
[infrastructure] deployment and configuration of Flink / Flink CDC (MySQL / es)

蓝桥杯 微生物增殖 C语言

潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe

零基础入门PolarDB-X:搭建高可用系统并联动数据大屏

A5000 vGPU显示模式切换

【翻译】云原生观察能力微调查。普罗米修斯引领潮流,但要了解系统的健康状况仍有障碍...
随机推荐
Leetcode 30. Concatenate substrings of all words
POJ 3207 Ikki's Story IV – Panda's Trick (2-SAT)
DaGAN论文解读
Hudi vs Delta vs Iceberg
Interview assault 63: how to remove duplication in MySQL?
Using clip path to draw irregular graphics
Use of deg2rad and rad2deg functions in MATLAB
IC设计流程中需要使用到的文件
Swiftui game source code Encyclopedia of Snake game based on geometryreader and preference
从sparse.csc.csr_matrix生成邻接矩阵
[calculating emotion and thought] floor sweeper, typist, information panic and Oppenheimer
关于图像的读取及处理等
Microservice architecture debate between radical technologists vs Project conservatives
Test Li hi
It's enough to read this article to analyze the principle in depth
CPU负载很低,loadavg很高处理方法
Reflection and illegalaccessexception exception during application
Problems encountered in using RT thread component fish
How to customize animation avatars? These six free online cartoon avatar generators are exciting at a glance!
Fast power template for inverse element, the role of inverse element and example [the 20th summer competition of Shanghai University Programming League] permutation counting