当前位置:网站首页>你不可不知道的Selenium 8种元素定位方法,简单且实用
你不可不知道的Selenium 8种元素定位方法,简单且实用
2022-07-06 18:48:00 【小梧敲代码】
自动化最基础的就属于定位元素了,元素不会定位,基本上已经团灭了,就不用再去考虑什么自动化了。
八大定位方法
Selenium定位元素基本上和appium的定位元素方法相同,这里基于百度网站进行测试。
id定位
通过了解HTML可以知道id是唯一表示,通过查找id的方法进行查找
find_element_by_id()
name定位
name在HTML中通常指元素的名称
find_element_by_name()
tag定位
通过HTML可以了解到tag定义不同页面的元素。
find_element_by_tag_name()
class定位
通过HTML了解到class是指元素的类名
find_element_by_class_name()
link_text定位
link_text从字面意思上了解到是通过文本的形式进行定位的
find_element_by_link_text()
partial_link定位
partial_link是属于link_text的补充定位方法,定位一些文本比较长的内容
find_element_by_partial_link_text()
xpath定位
xpath定位有多种定位策略,可以通过很多方法进行定位如:name,text,class等,后面可以单独进行写一篇关于Xpath的定位方法
find_element_by_xpath()
Css_selector定位
Css是一种语言,通常Css定位方法的速度比xpath的快,就是稍微有点难,爬虫中的pyquery就是通过Css的方法来实现的。
find_element_by_css_selector()
简单了介绍了八种定位方法,大家可以在实践中去尝试下,多动手去写代码,才能让代码能力更加熟练。
最后感谢每一个认真阅读我文章的人,下面这个网盘链接也是我费了几天时间整理的非常全面的,希望也能帮助到有需要的你!
这些资料,对于想转行做【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你!凡事要趁早,特别是技术行业,一定要提升技术功底。希望对大家有所帮助……
如果你不想一个人野蛮生长,找不到系统的资料,问题得不到帮助,坚持几天便放弃的感受的话,可以点击下方小卡片加入我们群,大家可以一起讨论交流,里面会有各种软件测试资料和技术交流。
点击文末小卡片领取 |
敲字不易,如果此文章对你有帮助的话,点个赞收个藏来个关注,给作者一个鼓励。也方便你下次能够快速查找。
自学推荐B站视频:
零基础转行软件测试:自学完软件测试,拿到了字节的测试岗offer,堪称B站最好的视频!
边栏推荐
- leetcode:736. Lisp 语法解析【花里胡哨 + 栈 + 状态enumaotu + slots】
- ZABBIX 5.0: automatically monitor Alibaba cloud RDS through LLD
- Lumion 11.0 software installation package download and installation tutorial
- Summer Challenge database Xueba notes (Part 2)~
- postgresql之整体查询大致过程
- 【论文阅读|深读】DNGR:Deep Neural Networks for Learning Graph Representations
- Introduction to the internal structure of the data directory of PostgreSQL
- 阿里云中间件开源往事
- 【森城市】GIS数据漫谈(二)
- postgresql之integerset
猜你喜欢
Web3对法律的需求
Infrared camera: juge infrared mag32 product introduction
豆瓣平均 9.x,分布式领域的 5 本神书!
阿里云中间件开源往事
FLIR blackfly s usb3 industrial camera: how to use counters and timers
云原生混部最后一道防线:节点水位线设计
The third season of ape table school is about to launch, opening a new vision for developers under the wave of going to sea
1 -- Xintang nuc980 nuc980 porting uboot, starting from external mx25l
String or binary data will be truncated
postgresql之整体查询大致过程
随机推荐
#yyds干货盘点# 解决名企真题:最大差值
Lombok同时使⽤@Data和@Builder 的坑
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
MySQL
Pioneer of Web3: virtual human
leetcode:5. 最长回文子串【dp + 抓着超时的尾巴】
STM32项目 -- 选题分享(部分)
[paper reading | deep reading] anrl: attributed network representation learning via deep neural networks
Processus général de requête pour PostgreSQL
所谓的消费互联网仅仅只是做行业信息的撮合和对接,并不改变产业本身
低代码平台中的数据连接方式(上)
String or binary data will be truncated
Yyds dry goods inventory # solve the real problem of famous enterprises: maximum difference
Argo workflows source code analysis
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
Word wrap when flex exceeds width
投资的再思考
Lumion 11.0 software installation package download and installation tutorial
C#/VB. Net to delete watermarks in word documents
Robot team learning method to achieve 8.8 times human return