当前位置:网站首页>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...'
边栏推荐
- National Eye Care Education Conference, 2022 the Fourth Beijing International Youth eye health industry exhibition
- 【数字IC验证快速入门】1、浅谈数字IC验证,了解专栏内容,明确学习目标
- Leetcode skimming: binary tree 16 (path sum)
- IC popular science article: those things about Eco
- Hong Kong stocks will welcome the "best ten yuan store". Can famous creative products break through through the IPO?
- 【数字IC验证快速入门】9、Verilog RTL设计必会的有限状态机(FSM)
- Ros2 topic [01]: installing ros2 on win10
- Leetcode brush question: binary tree 13 (the same tree)
- ROS2专题【01】:win10上安装ROS2
- Solve the problem that the database configuration information under the ThinkPHP framework application directory is still connected by default after modification
猜你喜欢

How to form standard interface documents

实操演示:产研团队如何高效构建需求工作流?

Rainbond 5.7.1 支持对接多家公有云和集群异常报警

小程序事件绑定
![[quick start of Digital IC Verification] 3. Introduction to the whole process of Digital IC Design](/img/92/7af0db21b3d7892bdc5dce50ca332e.png)
[quick start of Digital IC Verification] 3. Introduction to the whole process of Digital IC Design

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

Classic implementation method of Hongmeng system controlling LED

【数字IC验证快速入门】7、验证岗位中必备的数字电路基础知识(含常见面试题)

小程序页面导航

Enter the parallel world
随机推荐
Guidelines for application of Shenzhen green and low carbon industry support plan in 2023
Leetcode skimming: binary tree 10 (number of nodes of a complete binary tree)
Model method
插值查找的简单理解
Wechat applet regular expression extraction link
【愚公系列】2022年7月 Go教学课程 004-Go代码注释
本季度干货导航 | 2022年Q2
Y57. Chapter III kubernetes from entry to proficiency -- business image version upgrade and rollback (30)
Leetcode brush question: binary tree 14 (sum of left leaves)
Leetcode skimming: binary tree 16 (path sum)
鸿蒙系统控制LED的实现方法之经典
Solve the problem that the database configuration information under the ThinkPHP framework application directory is still connected by default after modification
Schema和Model
- Oui. Net Distributed Transaction and Landing Solution
sort和投影
Rainbond 5.7.1 支持对接多家公有云和集群异常报警
Point cloud file Dat file read save
2022 Beijing eye health products exhibition, eye care products exhibition, China eye Expo held in November
【刷题记录】1. 两数之和
Mongodb/ document operation