当前位置:网站首页>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"]')
边栏推荐
- How SVN views modified file records
- Javescript variable declaration -- VaR, let, const
- Kubernetes resource object introduction and common commands (V) - (NFS & PV & PVC)
- Electronic technology 20th autumn "Introduction to machine manufacturing" online assignment 3 [standard answer]
- Kubernetes resource object introduction and common commands (4)
- September, 19, "cam principle and application" online assignment [Full Score answer]
- IntelliJ 2021.3 short command line when running applications
- 1164 Good in C
- Dagong 21 autumn "power plant electrical part" online operation 1 [standard answer] power plant electrical part
- kubernetes资源对象介绍及常用命令(五)-(NFS&PV&PVC)
猜你喜欢

Depth first search of graph

大消费企业怎样做数字化转型?

New library online | cnopendata complete data of Chinese insurance institution outlets
![[RT thread] NXP rt10xx device driver framework -- Audio construction and use](/img/85/32a83eaa4b7f5b30d4d7c4f4c32791.png)
[RT thread] NXP rt10xx device driver framework -- Audio construction and use
![[RT thread] construction and use of --hwtimer of NXP rt10xx device driver framework](/img/df/a7719bcb00ff66e21f3a391ab94573.png)
[RT thread] construction and use of --hwtimer of NXP rt10xx device driver framework

kubernetes资源对象介绍及常用命令(四)

大变局!全国房价,跌破万元大关

图之深度优先搜索

Take you to API development by hand

设计电商秒杀
随机推荐
C language modifies files by line
SVN完全备份svnadmin hotcopy
Luogu: p2685 [tjoi2012] Bridge
Apache service suspended asynchronous acceptex failed
[combinatorics] recursive equation (general solution structure of recursive equation with multiple roots | linear independent solution | general solution with multiple roots | solution example of recu
Kubernetes resource object introduction and common commands (III)
First day of rhcsa study
Depth first search of graph
[combinatorics] recursive equation (characteristic equation and characteristic root | example of characteristic equation | root formula of monadic quadratic equation)
How to train mask r-cnn model with your own data
网络硬盘NFS的安装与配置
国内如何购买Google Colab会员
Define a structure fraction to represent a fraction, which is used to represent fractions such as 2/3 and 5/6
Talk about several methods of interface optimization
图之深度优先搜索
HP 阵列卡排障一例
University of Electronic Science and technology, accounting computerization, spring 20 final exam [standard answer]
鸿蒙第三次培训
Vs code plug-in korofileheader
kubernetes资源对象介绍及常用命令(三)