当前位置:网站首页>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)
边栏推荐
- selenium 元素定位(2)
- Flutter Doctor:Xcode 安装不完整
- Kubernetes stateless application expansion and contraction capacity
- Cookie concept, basic use, principle, details and Chinese transmission
- Leetcode skimming questions_ Invert vowels in a string
- Accelerating spark data access with alluxio in kubernetes
- 02.Go语言开发环境配置
- Maya hollowed out modeling
- internship:项目代码所涉及陌生注解及其作用
- A picture to understand! Why did the school teach you coding but still not
猜你喜欢
3D vision - 4 Getting started with gesture recognition - using mediapipe includes single frame and real time video
Alibaba canal usage details (pit draining version)_ MySQL and ES data synchronization
Redis-列表
MATLB|实时机会约束决策及其在电力系统中的应用
Unity | two ways to realize facial drive
Basic operations of database and table ----- set the fields of the table to be automatically added
Maya hollowed out modeling
About error 2003 (HY000): can't connect to MySQL server on 'localhost' (10061)
Huawei Hrbrid interface and VLAN division based on IP
[ssrf-01] principle and utilization examples of server-side Request Forgery vulnerability
随机推荐
02.Go语言开发环境配置
Remember that a version of @nestjs/typeorm^8.1.4 cannot be obtained Env option problem
3D vision - 4 Getting started with gesture recognition - using mediapipe includes single frame and real time video
Leetcode 208. Implement trie (prefix tree)
500 lines of code to understand the principle of mecached cache client driver
Reasonable and sensible
A picture to understand! Why did the school teach you coding but still not
Basic operations of database and table ----- set the fields of the table to be automatically added
[Yu Yue education] Liaoning Vocational College of Architecture Web server application development reference
How to upgrade kubernetes in place
Superfluid_ HQ hacked analysis
Docker compose配置MySQL并实现远程连接
Comments on flowable source code (XXXV) timer activation process definition processor, process instance migration job processor
Paddle框架:PaddleNLP概述【飛槳自然語言處理開發庫】
【Flask】官方教程(Tutorial)-part2:蓝图-视图、模板、静态文件
Alibaba-Canal使用详解(排坑版)_MySQL与ES数据同步
Flowable source code comments (36) process instance migration status job processor, BPMN history cleanup job processor, external worker task completion job processor
2 power view
Paddle framework: paddlenlp overview [propeller natural language processing development library]
Basic process and testing idea of interface automation