当前位置:网站首页>你不可不知道的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站最好的视频!
边栏推荐
- 建議收藏!!Flutter狀態管理插件哪家强?請看島上碼農的排行榜!
- B站6月榜单丨飞瓜数据UP主成长排行榜(哔哩哔哩平台)发布!
- SchedulX V1.4.0及SaaS版发布,免费体验降本增效高级功能!
- Word wrap when flex exceeds width
- 【森城市】GIS数据漫谈(二)
- Robot team learning method to achieve 8.8 times human return
- Introduction to RC oscillator and crystal oscillator
- fiddler的使用
- Data connection mode in low code platform (Part 1)
- 4 -- Xintang nuc980 mount initramfs NFS file system
猜你喜欢

大咖云集|NextArch基金会云开发Meetup来啦!
![leetcode:5. Longest palindrome substring [DP + holding the tail of timeout]](/img/62/d4d5428f69fc221063a4f607750995.png)
leetcode:5. Longest palindrome substring [DP + holding the tail of timeout]
![[paper reading | deep reading] rolne: improving the quality of network embedding with structural role proximity](/img/21/59c4d61b22e7d021b7a72a64a16b48.png)
[paper reading | deep reading] rolne: improving the quality of network embedding with structural role proximity

【论文阅读|深读】 GraphSAGE:Inductive Representation Learning on Large Graphs

Apifox,你的API接口文档卷成这样了吗?

3--新唐nuc980 kernel支持jffs2, Jffs2文件系统制作, 内核挂载jffs2, uboot网口设置,uboot支持tftp

【服务器数据恢复】raid损坏导致戴尔某型号服务器崩溃的数据恢复案例

postgresql之integerset

Jacob Steinhardt, assistant professor of UC Berkeley, predicts AI benchmark performance: AI has made faster progress in fields such as mathematics than expected, but the progress of robustness benchma

解密函数计算异步任务能力之「任务的状态及生命周期管理」
随机推荐
所谓的消费互联网仅仅只是做行业信息的撮合和对接,并不改变产业本身
6-6漏洞利用-SSH安全防御
Use of fiddler
FLIR blackfly s usb3 industrial camera: how to use counters and timers
Word wrap when flex exceeds width
[C # notes] reading and writing of the contents of text files
unity中跟随鼠标浮动的面板,并可以自适应文字内容的大小
postgresql 之 数据目录内部结构 简介
A new path for enterprise mid Platform Construction -- low code platform
Lumion 11.0软件安装包下载及安装教程
[paper reading | deep reading] anrl: attributed network representation learning via deep neural networks
3D laser slam: time synchronization of livox lidar hardware
leetcode:5. 最长回文子串【dp + 抓着超时的尾巴】
Douban average 9 x. Five God books in the distributed field!
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
Processus général de requête pour PostgreSQL
[unity] upgraded version · Excel data analysis, automatically create corresponding C classes, automatically create scriptableobject generation classes, and automatically serialize asset files
Lombok makes the pit of ⽤ @data and @builder at the same time
【论文阅读|深读】 GraphSAGE:Inductive Representation Learning on Large Graphs
A new path for enterprise mid Platform Construction -- low code platform