当前位置:网站首页>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...'
边栏推荐
- 鸿蒙os第四次学习
- CTF reverse Foundation
- 3.3、项目评估
- 炒股开户最低佣金,低佣金开户去哪里手机上开户安全吗
- Nprogress plug-in progress bar
- - Oui. Net Distributed Transaction and Landing Solution
- 14、Transformer--VIT TNT BETR
- 【数字IC验证快速入门】7、验证岗位中必备的数字电路基础知识(含常见面试题)
- Convolution free backbone network: Pyramid transformer to improve the accuracy of target detection / segmentation and other tasks (with source code)
- 强化学习-学习笔记4 | Actor-Critic
猜你喜欢

Zero cloud new UI design

【刷题记录】1. 两数之和

【愚公系列】2022年7月 Go教学课程 004-Go代码注释

Classic implementation method of Hongmeng system controlling LED

Rainbow 5.7.1 supports docking with multiple public clouds and clusters for abnormal alarms

Leetcode brush question: binary tree 14 (sum of left leaves)

About the priority of Bram IP reset

港股将迎“最牛十元店“,名创优品能借IPO突围?

Leetcode brush questions: binary tree 11 (balanced binary tree)

A solution to PHP's inability to convert strings into JSON
随机推荐
E. Singhal and numbers (prime factor decomposition)
【数字IC验证快速入门】9、Verilog RTL设计必会的有限状态机(FSM)
Model method
【数字IC验证快速入门】6、Questasim 快速上手使用(以全加器设计与验证为例)
Mysql频繁操作出现锁表问题
kubernetes资源对象介绍及常用命令(五)-(ConfigMap&Secret)
【UE4】UnrealInsight获取真机性能测试报告
Rainbow 5.7.1 supports docking with multiple public clouds and clusters for abnormal alarms
js方法传Long类型id值时会出现精确损失
Hongmeng OS' fourth learning
CTF reverse Foundation
[quick start of Digital IC Verification] 7. Basic knowledge of digital circuits necessary for verification positions (including common interview questions)
怎么挑选好的外盘平台,安全正规的?
model方法
走入并行的世界
Applet project structure
信息学奥赛一本通 1339:【例3-4】求后序遍历 | 洛谷 P1827 [USACO3.4] 美国血统 American Heritage
14、Transformer--VIT TNT BETR
【刷题记录】1. 两数之和
. Net distributed transaction and landing solution