当前位置:网站首页>Web-ui automated testing - the most complete element positioning method
Web-ui automated testing - the most complete element positioning method
2022-07-03 17:22:00 【Don't ask me y】
# BY.ID
driver = webdriver.Chrome()
driver.get("https://www.baidu.com/")
driver.find_element(By.ID, "kw").send_keys(" automation ")
# BY.NAME
driver.find_element(By.NAME, "wd").send_keys(" automation ")
# BY.LINK_TEXT, Link text
driver.find_element(By.LINK_TEXT, " Journalism ").click()
# BY.PARTIAL_LINK_TEXT, Some text links
driver.find_element(By.PARTIAL_LINK_TEXT, " new ").click()
# BY.XPATH location , There are five
# Relative paths + The index position
# location form Module first span Label under input
driver.find_element(By.XPATH, "//form/span[1]/input")
# Relative paths + Attribute positioning
driver.find_element(By.XPATH, "//[@autocomplete = 'off']")
# Relative paths + Wildcard positioning ,* The wildcard , Match all attribute values as off Properties of
driver.find_element(By.XPATH, "//*[@* = 'off']")
driver.find_element(By.XPATH, "//*[@autocomplete = 'off']")
# Relative paths + Partial attribute value positioning , Attributes should be unique
driver.find_element(By.XPATH, "//*[starts-with(@autocomplete.'ff')]")
driver.find_element(By.XPATH, "//*[substring(@autocomplete,2) = 'ff']")
driver.find_element(By.XPATH, "//*[contains(@autocomplete ,'ff')]")
# Relative paths + Text label value positioning
driver.find_element(By.XPATH, "//span[text() = ' Search by picture ']")
# Combined positioning
# Tag name #id Property value : Refers to the input Under the label id The attribute is kw The elements of
driver.find_element_by_css_selector("input#kw")
# Tag name .class Property value : Refers to the input Under the label class The attribute is s_ipt The elements of
driver.find_element_by_css_selector("input.s_ipt")
# Tag name [ attribute =’ Property value ‘]: Refers to the input Under the label name The attribute is wd The elements of
driver.find_element_by_css_selector('input[name="wd"]')
# Parent element tag name > Tag name .class Property value : refer to span Under the input Under the label class The attribute is s_ipt The elements of
driver.find_element_by_css_selector("span>input.s_ipt")
# Multiple attribute combinations locate elements ( Commonly used )
# refer to input Under the label id The attribute is kw And name The attribute is wd The elements of
driver.find_element_by_css_selector('input.s_ipt[name="wd”]')
# refer to input Under the label name The attribute is wd And maxlength by 100 The elements of
driver.find_element_by_css_selector('input[name="wd"][maxlength="100"]')
边栏推荐
- 跨境电商:外贸企业做海外社媒营销的优势
- First day of rhcsa study
- 2021 ICPC regional competition (Shanghai) g.edge groups (tree DP)
- [combinatorics] recursive equation (example of solving recursive equation without multiple roots | complete process of solving recursive equation without multiple roots)
- RedHat 6.2 configuring ZABBIX
- 定义一个结构体Fraction,表示分数,用于表示 2/3, 5/6这样的分数
- How to read the source code [debug and observe the source code]
- One brush 144 force deduction hot question-1 sum of two numbers (E)
- UE4 official charging resources, with a total price of several thousand
- Hongmeng third training
猜你喜欢
TensorBoard快速入门(Pytorch使用TensorBoard)
Prepare for the golden three silver four, 100+ software test interview questions (function / interface / Automation) interview questions. win victory the moment one raises one 's standard
How to train mask r-cnn model with your own data
Redis:关于列表List类型数据的操作命令
ANOVA example
跨境电商:外贸企业做海外社媒营销的优势
Life is still confused? Maybe these subscription numbers have the answers you need!
【RT-Thread】nxp rt10xx 设备驱动框架之--hwtimer搭建和使用
[error reporting] omp: error 15: initializing libiomp5md dll, but found libiomp5md. dll already initialized.
How to read the source code [debug and observe the source code]
随机推荐
27. 输入3个整数,按从大到小的次序输出。要求用指针方法实现。
【RT-Thread】nxp rt10xx 设备驱动框架之--rtc搭建和使用
聊聊接口优化的几个方法
Examination questions for the assignment of selected readings of British and American Literature in the course examination of Fujian Normal University in February 2022
One brush 149 force deduction hot question-10 regular expression matching (H)
PS screen printing brush 131, many illustrators have followed suit
C language modifies files by line
One brush 144 force deduction hot question-1 sum of two numbers (E)
Golang单元测试、Mock测试以及基准测试
SVN完全备份svnadmin hotcopy
跨境电商:外贸企业做海外社媒营销的优势
Hongmeng fourth training
绝对定位时元素水平垂直居中
SWM32系列教程4-端口映射及串口应用
27. Input 3 integers and output them in descending order. Pointer method is required.
visual studio “通常每个套接字地址(协议/网络地址/端口)只允许使用一次“
定义一个结构体Fraction,表示分数,用于表示 2/3, 5/6这样的分数
Leetcode13. Roman numeral to integer (three solutions)
2021 ICPC regional competition (Shanghai) g.edge groups (tree DP)
Answer to the homework assessment of advanced English reading (II) of the course examination of Fuzhou Normal University in February 2022