当前位置:网站首页>Selenium element information
Selenium element information
2022-07-05 20:35:00 【Live up to your youth】
summary
When passed selenium After locating a specific element , You can get many details of this element , For example, the css style 、 Tag name 、 Text and get the child elements of this element, etc .
function
Whether the element is displayed
element.is_displayed()
This method is used to check whether the connected element is correctly displayed on the web page . Returns a Boolean value , If the connected element is displayed in the current browser context , Then for True; Otherwise return to False.
>>> from selenium import webdriver
>>> from selenium.common import By
>>> driver = webdriver.Chrome()
>>> driver.get("https://www.example.com")
>>> element = driver.find_element(By.TAG_NAME, "p")
# Judge whether the element displays
>>> element.is_displayed()
True
Whether the element is selected
element.is_selected()
This method determines whether the referenced element has been selected . This method is widely used in check boxes 、 Radio button 、 Input element and option element . Returns a Boolean value , If in the current browsing context Have chosen Referenced element , Then return to True, Otherwise return to False.
Get element attribute value
element.get_attribute(name)
Used to get the attribute value of the element . such as name attribute 、id attribute 、class attribute 、href Properties and so on .
>>> from selenium import webdriver
>>> from selenium.common import By
>>> driver = webdriver.Chrome()
>>> driver.get("https://www.example.com")
>>> element = driver.find_elements(By.TAG_NAME, "p")[1]
>>> element = element.find_element(By.TAG_NAME, "a")
# obtain href attribute
>>> element.get_attribute("href")
'https://www.iana.org/domains/example'
Get the element tag name
element.tag_name
This method is used to get The tag name of the referenced element with focus .
>>> from selenium import webdriver
>>> from selenium.common import By
>>> driver = webdriver.Chrome()
>>> driver.get("https://www.example.com")
>>> element = driver.find_element(By.TAG_NAME, "p")
# Get the tag name
>>> element.tag_name
'p'
Get element text
element.text
Get the rendered text of a specific element .
>>> from selenium import webdriver
>>> from selenium.common import By
>>> driver = webdriver.Chrome()
>>> driver.get("https://www.example.com")
>>> element = driver.find_element(By.TAG_NAME, "p")
# Get element text
>>> element.text
'This domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.'
Get elements css style
element.value_of_css_property(property_name)
Gets the value of the specific calculation style attribute of the element in the current browsing context .
>>> from selenium import webdriver
>>> from selenium.common import By
>>> driver = webdriver.Chrome()
>>> driver.get("https://www.example.com")
>>> element = driver.find_element(By.TAG_NAME, "p")
# Get the text color of the element
>>> element.value_of_css_property("color")
'rgba(0, 0, 0, 1)'
Get element rectangle
element.rect
Used to obtain the dimensions and coordinates of the reference element . The extracted data body contains X Axis position 、 In the upper left corner of the element y Axis position 、 Height of element 、 Element width .
>>> from selenium import webdriver
>>> from selenium.common import By
>>> driver = webdriver.Chrome()
>>> driver.get("https://www.example.com")
>>> element = driver.find_element(By.TAG_NAME, "p")
# Get the rectangular coordinates of the element
>>> element.rect
{'height': 60, 'width': 418, 'x': 32, 'y': 115.67500305175781}
Get element child elements
element.find_element()
Used to find matching child elements in the context of parent elements (WebElement).
>>> from selenium import webdriver
>>> from selenium.common import By
>>> driver = webdriver.Chrome()
>>> driver.get("https://www.example.com")
>>> element = driver.find_elements(By.TAG_NAME, "p")[1]
# Get the child elements of the element
>>> element = element.find_element(By.TAG_NAME, "a")
>>> element.text
'More information...'
边栏推荐
- js方法传Long类型id值时会出现精确损失
- sort和投影
- 【数字IC验证快速入门】3、数字IC设计全流程介绍
- kubernetes资源对象介绍及常用命令(五)-(ConfigMap&Secret)
- Rainbond 5.7.1 支持对接多家公有云和集群异常报警
- 【数字IC验证快速入门】6、Questasim 快速上手使用(以全加器设计与验证为例)
- USACO3.4 “破锣摇滚”乐队 Raucous Rockers - DP
- Y57. Chapter III kubernetes from entry to proficiency -- business image version upgrade and rollback (30)
- Common view container class components
- mongodb/文档操作
猜你喜欢
关于BRAM IP复位的优先级
1. Strengthen learning basic knowledge points
2.8、项目管理过程基础知识
JS implementation prohibits web page zooming (ctrl+ mouse, +, - zooming effective pro test)
Introduction to dead letter queue (two consumers, one producer)
Convolution free backbone network: Pyramid transformer to improve the accuracy of target detection / segmentation and other tasks (with source code)
如何形成规范的接口文档
无卷积骨干网络:金字塔Transformer,提升目标检测/分割等任务精度(附源代码)...
[quick start of Digital IC Verification] 7. Basic knowledge of digital circuits necessary for verification positions (including common interview questions)
【数字IC验证快速入门】8、数字IC中的典型电路及其对应的Verilog描述方法
随机推荐
Introduction to dead letter queue (two consumers, one producer)
全国爱眼教育大会,2022第四届北京国际青少年眼健康产业展会
Is it safe for Galaxy Securities to open an account online?
- Oui. Net Distributed Transaction and Landing Solution
Rainbow 5.7.1 supports docking with multiple public clouds and clusters for abnormal alarms
Reinforcement learning - learning notes 4 | actor critical
Dry goods navigation in this quarter | Q2 2022
National Eye Care Education Conference, 2022 the Fourth Beijing International Youth eye health industry exhibition
Fundamentals - configuration file analysis
Leetcode(347)——前 K 个高频元素
如何形成规范的接口文档
【愚公系列】2022年7月 Go教学课程 004-Go代码注释
1. Strengthen learning basic knowledge points
Leetcode (695) - the largest area of an island
走入并行的世界
Ros2 topic [01]: installing ros2 on win10
[quick start of Digital IC Verification] 6. Quick start of questasim (taking the design and verification of full adder as an example)
[quick start of Digital IC Verification] 9. Finite state machine (FSM) necessary for Verilog RTL design
Scala basics [HelloWorld code parsing, variables and identifiers]
IC popular science article: those things about Eco