当前位置:网站首页>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...'
边栏推荐
- Is it safe to open an account online? Where can I get a low commission?
- 2022北京眼睛健康用品展,护眼产品展,中国眼博会11月举办
- IC popular science article: those things about Eco
- Pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs
- Schema和Model
- Applet event binding
- 【数字IC验证快速入门】2、通过一个SoC项目实例,了解SoC的架构,初探数字系统设计流程
- 小程序项目结构
- Introduction to dead letter queue (two consumers, one producer)
- How to form standard interface documents
猜你喜欢
随机推荐
欢迎来战,赢取丰厚奖金:Code Golf 代码高尔夫挑战赛正式启动
Leetcode: binary tree 15 (find the value in the lower left corner of the tree)
【数字IC验证快速入门】1、浅谈数字IC验证,了解专栏内容,明确学习目标
【数字IC验证快速入门】6、Questasim 快速上手使用(以全加器设计与验证为例)
Schema和Model
Leetcode skimming: binary tree 10 (number of nodes of a complete binary tree)
National Eye Care Education Conference, 2022 the Fourth Beijing International Youth eye health industry exhibition
js方法传Long类型id值时会出现精确损失
炒股开户最低佣金,低佣金开户去哪里手机上开户安全吗
Hong Kong stocks will welcome the "best ten yuan store". Can famous creative products break through through the IPO?
E. Singhal and numbers (prime factor decomposition)
Minimum commission for stock trading account opening, where to open an account with low commission? Is it safe to open an account on your mobile phone
B站UP搭建世界首个纯红石神经网络、基于深度学习动作识别的色情检测、陈天奇《机器学编译MLC》课程进展、AI前沿论文 | ShowMeAI资讯日报 #07.05
CTF reverse Foundation
model方法
Is it safe for Galaxy Securities to open an account online?
Model method
Codeforces Round #804 (Div. 2) - A, B, C
2020 CCPC 威海 - A. Golden Spirit(思维),D. ABC Conjecture(大数分解 / 思维)
[quick start of Digital IC Verification] 1. Talk about Digital IC Verification, understand the contents of the column, and clarify the learning objectives