当前位置:网站首页>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)
边栏推荐
- How to access localhost:8000 by mobile phone
- js实现力扣71题简化路径
- Phoenix Architecture 2 - accessing remote services
- Mysql Information Schema 學習(一)--通用錶
- Tensorflow2.0 自定义训练的方式求解函数系数
- Vmware虚拟机无法打开内核设备“\\.\Global\vmx86“的解决方法
- 通俗的讲解,带你入门协程
- LeetCode_ Double pointer_ Medium_ 61. rotating linked list
- It's super detailed in history. It's too late for you to read this information if you want to find a job
- Leetcode 30. 串联所有单词的子串
猜你喜欢

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

手把手教你学会js的原型与原型链,猴子都能看懂的教程

Information System Project Manager - Chapter VIII project quality management

Low CPU load and high loadavg processing method

Swiftui game source code Encyclopedia of Snake game based on geometryreader and preference
Application of clock wheel in RPC

zabbix 代理服务器 与 zabbix-snmp 监控

ZABBIX proxy server and ZABBIX SNMP monitoring

系统性详解Redis操作Hash类型数据(带源码分析及测试结果)

Carte de réflexion + code source + notes + projet, saut d'octets + jd + 360 + tri des questions d'entrevue Netease
随机推荐
黑馬--Redis篇
Spark foundation -scala
腾讯T3大牛手把手教你,大厂内部资料
[translation] micro survey of cloud native observation ability. Prometheus leads the trend, but there are still obstacles to understanding the health of the system
[translation] Digital insider. Selection process of kubecon + cloudnativecon in Europe in 2022
手把手教你学会js的原型与原型链,猴子都能看懂的教程
Swagger2 reports an error illegal DefaultValue null for parameter type integer
激进技术派 vs 项目保守派的微服务架构之争
1805. 字符串中不同整数的数目
JDBC详解
Tencent Android interview must ask, 10 years of Android development experience
CF960G - Bandit Blues(第一类斯特林数+OGF)
Translation D28 (with AC code POJ 26:the nearest number)
Teach you to learn JS prototype and prototype chain hand in hand, a tutorial that monkeys can understand
Carte de réflexion + code source + notes + projet, saut d'octets + jd + 360 + tri des questions d'entrevue Netease
算法面试经典100题,Android程序员最新职业规划
Phoenix Architecture 2 - accessing remote services
The "white paper on the panorama of the digital economy" has been released with great emphasis on the digitalization of insurance
潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe
【翻译】云原生观察能力微调查。普罗米修斯引领潮流,但要了解系统的健康状况仍有障碍...