当前位置:网站首页>Selenium element positioning (2)
Selenium element positioning (2)
2022-07-06 01:38:00 【Live up to your youth】
summary
selenium 4 Relative locator is introduced ( Formerly known as friendly locator ). When it's not easy to build locators for the required elements , These locators are very helpful , But it's easy to spatially describe the position of elements relative to elements with easy to build locators .
The way
above
locate_with(by: By, using: str).above(element_or_locator:Union[WebElement, Dict] = None)
If an element is not easy to locate , But the element below this element is easy to locate , Then you can access the element below this element first , Re pass above Function to access the element .
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.relative_locator import locate_with
driver = webdriver.Chrome()
driver.get("http://www.example.com")
# Navigate to the label named p The elements of
element = driver.find_element(By.TAG_NAME, "p")
# Relative positioning to the element, the tag name is h1 The elements of
locator = locate_with(By.TAG_NAME, "h1").above(element)
# Find elements based on relative positioning
element = driver.find_element(locator)
below
locate_with(by: By, using: str).below(element_or_locator:Union[WebElement, Dict] = None)
If an element is not easy to locate , But the elements above this element are easy to locate , Then you can access the element above this element first , Re pass below Function to access the element .
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.relative_locator import locate_with
driver = webdriver.Chrome()
driver.get("http://www.example.com")
element = driver.find_element(By.TAG_NAME, "h1")
# Relative positioning to element The label below is p Elements
locator = locate_with(By.TAG_NAME, "p").below(element)
element = driver.find_element(locator)
left
locate_with(by: By, using: str).to_left_of(element_or_locator:Union[WebElement, Dict] = None)
If an element is not easy to locate , But the element on the right of this element is easy to locate , Then you can access the element on the right of the element first , Re pass to_left_of Function to access the element .
right
locate_with(by: By, using: str).to_right_of(element_or_locator:Union[WebElement, Dict] = None)
If an element is not easy to locate , But the element on the left of this element is easy to locate , Then you can access the element on the left of the element first , Re pass to_right_of Function to access the element .
near
locate_with(by: By, using: str).near(element_or_locator:Union[WebElement, Dict] = None)
If the relative positioning is not obvious , Or change according to the size of the window , have access to near Method to identify distance elements at most 50px The elements of .
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.relative_locator import locate_with
driver = webdriver.Chrome()
driver.get("http://www.example.com")
element = driver.find_element(By.TAG_NAME, "h1")
# Relative positioning to element near ( It can be up and down, left and right ) The tag name of the is p The elements of
locator = locate_with(By.TAG_NAME, "p").near(element)
element = driver.find_element(locator)
边栏推荐
- dried food! Accelerating sparse neural network through hardware and software co design
- You are using pip version 21.1.1; however, version 22.0.3 is available. You should consider upgradin
- 【Flask】官方教程(Tutorial)-part1:项目布局、应用程序设置、定义和访问数据库
- Internship: unfamiliar annotations involved in the project code and their functions
- 【SSRF-01】服务器端请求伪造漏洞原理及利用实例
- False breakthroughs in the trend of London Silver
- 网易智企逆势进场,游戏工业化有了新可能
- 插卡4G工业路由器充电桩智能柜专网视频监控4G转以太网转WiFi有线网速测试 软硬件定制
- 2022年广西自治区中职组“网络空间安全”赛题及赛题解析(超详细)
- Basic operations of database and table ----- delete data table
猜你喜欢
False breakthroughs in the trend of London Silver
1. Introduction to basic functions of power query
MATLB|实时机会约束决策及其在电力系统中的应用
一圖看懂!為什麼學校教了你Coding但還是不會的原因...
Poj2315 football games
Accelerating spark data access with alluxio in kubernetes
[understanding of opportunity-39]: Guiguzi - Chapter 5 flying clamp - warning 2: there are six types of praise. Be careful to enjoy praise as fish enjoy bait.
NLP第四范式:Prompt概述【Pre-train,Prompt(提示),Predict】【刘鹏飞】
Alibaba-Canal使用详解(排坑版)_MySQL与ES数据同步
leetcode刷题_平方数之和
随机推荐
CocoaPods could not find compatible versions for pod 'Firebase/CoreOnly'
Redis-列表
02.Go语言开发环境配置
Basic operations of database and table ----- delete data table
Docker compose configures MySQL and realizes remote connection
Loop structure of program (for loop)
SPIR-V初窺
DOM introduction
Basic operations of databases and tables ----- default constraints
竞赛题 2022-6-26
Code Review关注点
3D视觉——4.手势识别(Gesture Recognition)入门——使用MediaPipe含单帧(Singel Frame)和实时视频(Real-Time Video)
Unity | two ways to realize facial drive
[技术发展-28]:信息通信网大全、新的技术形态、信息通信行业高质量发展概览
正则表达式:示例(1)
Basic operations of databases and tables ----- unique constraints
Luo Gu P1170 Bugs Bunny and Hunter
Cadre du Paddle: aperçu du paddlelnp [bibliothèque de développement pour le traitement du langage naturel des rames volantes]
[understanding of opportunity-39]: Guiguzi - Chapter 5 flying clamp - warning 2: there are six types of praise. Be careful to enjoy praise as fish enjoy bait.
剑指 Offer 12. 矩阵中的路径