当前位置:网站首页>你不可不知道的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站最好的视频!
边栏推荐
- String or binary data will be truncated
- 【Unity】升级版·Excel数据解析,自动创建对应C#类,自动创建ScriptableObject生成类,自动序列化Asset文件
- 进程管理基础
- fiddler的使用
- Douban average 9 x. Five God books in the distributed field!
- Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
- 【论文阅读|深读】RolNE: Improving the Quality of Network Embedding with Structural Role Proximity
- leetcode:736. Lisp 语法解析【花里胡哨 + 栈 + 状态enumaotu + slots】
- The empirical asset pricing package (EAP) can be installed through pypi
- unity中跟随鼠标浮动的面板,并可以自适应文字内容的大小
猜你喜欢

Web3对法律的需求
![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]

Ali yunyili: how does yunyuansheng solve the problem of reducing costs and improving efficiency?

C#/VB.NET 删除Word文档中的水印

Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem

Lumion 11.0软件安装包下载及安装教程

Linear list --- circular linked list

老板被隔离了

C语言练习题_1

【论文阅读|深读】 GraphSAGE:Inductive Representation Learning on Large Graphs
随机推荐
Several classes and functions that must be clarified when using Ceres to slam
1--新唐nuc980 NUC980移植 UBOOT,从外部mx25l启动
leetcode:736. Lisp 语法解析【花里胡哨 + 栈 + 状态enumaotu + slots】
Integerset of PostgreSQL
The boss is quarantined
Overall query process of PostgreSQL
This week's hot open source project!
postgresql 之 数据目录内部结构 简介
fiddler的使用
Leetcode:minimum_depth_of_binary_tree解决问题的方法
[C # notes] use file stream to copy files
unity 自定义webgl打包模板
[paper reading | deep reading] dngr:deep neural networks for learning graph representations
Web开发小妙招:巧用ThreadLocal规避层层传值
SchedulX V1.4.0及SaaS版发布,免费体验降本增效高级功能!
【论文阅读|深读】DNGR:Deep Neural Networks for Learning Graph Representations
postgresql之整體查詢大致過程
Douban average 9 x. Five God books in the distributed field!
Use of pgpool II and pgpooladmin
CDB PDB 用户权限管理