当前位置:网站首页>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"]')
边栏推荐
- [combinatorics] recursive equation (example of solving recursive equation without multiple roots | complete process of solving recursive equation without multiple roots)
- [combinatorics] recursive equation (special solution example 1 Hannover tower complete solution process | special solution example 2 special solution processing when the characteristic root is 1)
- Free data | new library online | cnopendata complete data of China's insurance intermediary outlets
- Redis: operation commands for list type data
- Financial management (Higher Vocational College) financial management online Assignment 1 in autumn 20
- A day's work list of an ordinary programmer
- QT学习日记9——对话框
- kubernetes资源对象介绍及常用命令(五)-(NFS&PV&PVC)
- 互联网医院HIS管理平台源码,在线问诊,预约挂号 智慧医院小程序源码
- The difference between get and post
猜你喜欢
![[try to hack] active detection and concealment technology](/img/43/d48f851268fec566ce0cc83bd9557e.png)
[try to hack] active detection and concealment technology

鸿蒙第三次培训

Kubernetes resource object introduction and common commands (III)

Unity notes unityxr simple to use

新库上线 | CnOpenData中国保险机构网点全集数据

IntelliJ 2021.3 short command line when running applications

Qt调节Win屏幕亮度和声音大小

POM in idea XML graying solution

UE4 official charging resources, with a total price of several thousand

Golang unit test, mock test and benchmark test
随机推荐
An example of HP array card troubleshooting
C language modifies files by line
One brush 149 force deduction hot question-10 regular expression matching (H)
Select 3 fcpx plug-ins. Come and see if you like them
Wechat applet for the first time
One brush 144 force deduction hot question-1 sum of two numbers (E)
PR second time
One brush 147-force deduction hot question-4 find the median of two positive arrays (H)
C语言字符串练习
[RT thread] NXP rt10xx device driver framework -- pin construction and use
What is your income level in the country?
Pools de Threads: les composants les plus courants et les plus sujets aux erreurs du Code d'affaires
设计电商秒杀
Rsync remote synchronization
New library online | cnopendata complete data of Chinese insurance institution outlets
【RT-Thread】nxp rt10xx 设备驱动框架之--rtc搭建和使用
Visual studio "usually, each socket address (Protocol / network address / port) can only be used once“
[UE4] brush Arctic pack high quality Arctic terrain pack
【Try to Hack】主动侦查隐藏技术
Electronic Science and technology 20th autumn "Microcomputer Principle and application" online assignment 2 [standard answer]