当前位置:网站首页>Selenium:元素定位
Selenium:元素定位
2022-08-01 04:59:00 【不怕猫的耗子A】
Selenium自动化测试
1、Selenium对网页的控制是基于各种前端元素的,在使用过程中,对于元素的定位是基础,只有准确抓取到对应元素才能进行后续的自动化控制
⑴前面介绍了前端网页HTML是由很多标签元素有层级的组成的,对于某一个标签它在整个网页HTML中的位置是唯一的,因此可以通过某些方法准确的找到这个标签元素并操作它
⑵使用WebDriver对象的find_element_by_*函数可以定位一个Web页面元素
⑶使用WebDriver对象的find_elements_by_*函数可以定位多个Web页面元素
2、自动化测试步骤:定位元素->操作元素->验证操作结果->记录测试结果
定位单个元素
1、在操作浏览器时较多时候我们仅仅需要定位某一个元素,因此WebDriver提供很多定位单个元素的方法
2、使用Selenium打开一个网页后(get方法返回值)会返回一个WebDriver对象,可以使用该对象下的定位方法来定位某一个元素
3、这些方法都是通过标签的某一属性来定位元素的,因此这些方法有统一的返回值:
⑴找到元素:返回对应元素的WebElement对象
⑵未找到元素:返回NoSuchElementException异常
4、在定位到一个元素后,就需要我们对这个元素进行一些操作了,这里就会使
边栏推荐
- Pyspark Machine Learning: Vectors and Common Operations
- Swastika line-by-line parsing and realization of the Transformer, and German translation practice (a)
- MySQL实践总结-
- Immutable
- HJS-DE1/2时间继电器
- 数组问题之《下一个排列》、《旋转图像》以及二分查找之《搜索二维矩阵》
- typescript22-接口继承
- 2022年超全的Android面经(附含面试题|进阶资料)
- API Design Notes: The pimpl trick
- 备战金九银十,如何顺利通过互联网大厂Android的笔面试?
猜你喜欢

律师解读 | 枪炮还是玫瑰?从大厂之争谈元宇宙互操作性

UE4 制作遇到的问题

可持久化线段树

(2022牛客多校四)K-NIO‘s Sword(思维)

Pyspark机器学习:向量及其常用操作

Logitech Mouse Experience Record

UE4 rays flashed from mouse position detection

Lawyer Interpretation | Guns or Roses?Talking about Metaverse Interoperability from the Battle of Big Manufacturers

(Codeforce 757) E. Bash Plays with Functions

typescript23-tuple
随机推荐
In the shake database, I want to synchronize the data of the source db0 to the destination db5, how to set the parameters?
UE4 制作遇到的问题
Dry goods!How to Construct SRv6-TE Performance Test Environment Using Instrumentation
Logitech Mouse Experience Record
pytorch、tensorflow对比学习—计算图和微分机制
解决ffmpeg使用screen-capture-recorder录屏,有屏幕缩放的情况下录不全的问题
typescript22-接口继承
API Design Notes: The pimpl trick
The Flow Of Percona Toolkit pt-table-checksum
PMP 项目资源管理
MySQL Practice Summary -
这里有110+公开的专业数据集
Progressive Reconstruction of Visual Structure for Image Inpainting 论文笔记
Power button (LeetCode) 212. The word search II (2022.07.31)
pytroch、tensorflow对比学习—搭建模型范式(低阶、中阶、高阶API示例)
(Codeforce 757) E. Bash Plays with Functions
基于Arduino制作非接触式测温仪
Immutable
【云原生之kubernetes实战】kubernetes集群的检测工具——popeye
PMP子过程定义总结