当前位置:网站首页>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...'
边栏推荐
- Unity编辑器扩展 UI控件篇
- 插值查找的简单理解
- .Net分布式事务及落地解决方案
- Leetcode (695) - the largest area of an island
- mongodb文档间关系
- Sort and projection
- 【数字IC验证快速入门】7、验证岗位中必备的数字电路基础知识(含常见面试题)
- 3.3 project evaluation
- Scala basics [HelloWorld code parsing, variables and identifiers]
- Leetcode brush questions: binary tree 11 (balanced binary tree)
猜你喜欢
关于BRAM IP复位的优先级
Oracle tablespace management
About the priority of Bram IP reset
Leetcode brush questions: binary tree 11 (balanced binary tree)
Classic implementation of the basic method of intelligent home of Internet of things
National Eye Care Education Conference, 2022 the Fourth Beijing International Youth eye health industry exhibition
2.8、项目管理过程基础知识
【数字IC验证快速入门】8、数字IC中的典型电路及其对应的Verilog描述方法
Make Jar, Not War
Make Jar, Not War
随机推荐
Mysql频繁操作出现锁表问题
Introduction to dead letter queue (two consumers, one producer)
实操演示:产研团队如何高效构建需求工作流?
1. Strengthen learning basic knowledge points
小程序全局配置
14、Transformer--VIT TNT BETR
Leetcode skimming: binary tree 17 (construct binary tree from middle order and post order traversal sequence)
证券开户选择哪个证券比较好?网上开户安全么?
基础篇——配置文件解析
2.8 basic knowledge of project management process
Composition of applet code
JS implementation prohibits web page zooming (ctrl+ mouse, +, - zooming effective pro test)
[record of question brushing] 1 Sum of two numbers
【UE4】UnrealInsight获取真机性能测试报告
零道云新UI设计中
Informatics Orsay all in one 1339: [example 3-4] find the post order traversal | Valley p1827 [usaco3.4] American Heritage
July 4, 2022 - July 10, 2022 (UE4 video tutorial MySQL)
Informatics Olympiad 1338: [example 3-3] hospital setting | Luogu p1364 hospital setting
Hongmeng OS' fourth learning
Codeforces Round #804 (Div. 2) - A, B, C