当前位置:网站首页>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"]')
边栏推荐
猜你喜欢
大变局!全国房价,跌破万元大关
互联网医院HIS管理平台源码,在线问诊,预约挂号 智慧医院小程序源码
TensorBoard快速入门(Pytorch使用TensorBoard)
Is AI too slow to design pictures and draw illustrations? 3 sets of practical brushes to save you
Luogu: p1155 [noip2008 improvement group] double stack sorting (bipartite graph, simulation)
问题随记 —— 在 edge 上看视频会绿屏
Play with fancy special effects. This AE super kit is for you
[RT thread] NXP rt10xx device driver framework -- pin construction and use
Redis:关于列表List类型数据的操作命令
Select 3 fcpx plug-ins. Come and see if you like them
随机推荐
Online assignment 3 of mobile Internet technology in the 20th autumn of electronic technology [standard answer]
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 read the source code [debug and observe the source code]
C语言字符串练习
[combinatorics] recursive equation (the problem of solving recursive equation with multiple roots | the problem is raised)
[RT thread] NXP rt10xx device driver framework -- Audio construction and use
RDS数据库的监测页面在哪看?
AcWing 3438. 数制转换
Analysis of variance summary
Stm32h7 Hal library SPI DMA transmission has been in busy solution
One brush 142 monotone stack next larger element II (m)
【RT-Thread】nxp rt10xx 设备驱动框架之--Pin搭建和使用
27. 输入3个整数,按从大到小的次序输出。要求用指针方法实现。
STM32H7 HAL库SPI DMA发送一直处于busy的解决办法
RedHat 6.2 configuring ZABBIX
Great changes! National housing prices fell below the 10000 yuan mark
Hongmeng fourth training
在iptables防火墙下开启vsftpd的端口
One brush 145 force deduction hot question-2 sum of two numbers (m)
Dagong 21 autumn "power plant electrical part" online operation 1 [standard answer] power plant electrical part