当前位置:网站首页>Selenium面试题分享
Selenium面试题分享
2022-06-12 09:07:00 【软件测试老莫】
目录
2、selenium中hidden或者是display = none的元素是否可以定位到?
3、selenium中如何保证操作元素的成功率?也就是说如何保证我点击的元素一定是可以点击的?
5、id,name,clas,xpath, css selector这些属性,你最偏爱哪一种,为什么?
1、selenium中如何判断元素是否存在?
selenium中没有提供原生的方法判断元素是否存在,一般我们可以通过定位元素+异常捕获的方式判断。
# 判断元素是否存在
try:dr.find_element_by_id('none')except NoSuchElementException:print 'element does not exist'
2、selenium中hidden或者是display = none的元素是否可以定位到?
不可以,selenium不能定位不可见的元素。display=none的元素实际上是不可见元素。
3、selenium中如何保证操作元素的成功率?也就是说如何保证我点击的元素一定是可以点击的?
- 当网速不好的情况下,使用合适的等待时间
- 被点击的元素一定要占一定的空间,因为selenium默认会去点这个元素的中心点,不占空间的元素算不出来中心点;
- 被点击的元素不能被其他元素遮挡;
- 被点击的元素不能在viewport之外,也就是说如果元素必须是可见的或者通过滚动条操作使得元素可见;
- 判断元素是否是可以被点击的
如何提高selenium脚本的执行速度?
- 使用更高配置的电脑和选择更快的网络环境
- 使用效率更高的语言,比如java执行速度就快过python
- 优化代码
- 不要盲目的加sleep,尽量使用显式等待
- 对于firefox,考虑使用测试专用的profile,因为每次启动浏览器的时候firefox会创建1个新的profile,对于这个新的profile,所有的静态资源都是从服务器直接下载,而不是从缓存里加载,这就导致网络不好的时候用例运行速度特别慢的问题
- chrome浏览器和safari浏览器的执行速度看上去是最快的
- 可以考虑分布式执行或者使用selenium grid
用例在运行过程中经常会出现不稳定的情况,也就是说这次可以通过,下次就没办法通过了,如何去提升用例的稳定性?
- 测试专属profile,尽量让静态资源缓存
- 尽量使用显式等待
- 尽量使用测试专用环境,避免其他类型的测试同时进行,对数据造成干扰
你的自动化用例的执行策略是什么?
- 每日执行:比如每天晚上在主干执行一次
- 周期执行:每隔2小时在开发分之执行一次
- 动态执行:每次代码有提交就执行
4、自动化测试的时候是不是需要连接数据库做数据校验?
一般不需要,因为这是单元测试层做的事情,在自动化测试层尽量不要为单元测试层没做的工作还债。
5、id,name,clas,xpath, css selector这些属性,你最偏爱哪一种,为什么?
xpath和css最为灵活,所以其他的答案都不够完美。
6、如何去定位页面上动态加载的元素?
显式等待
7、如何去定位属性动态变化的元素?
找出属性动态变化的规律,然后根据上下文生成动态属性。
点击链接以后,selenium是否会自动等待该页面加载完毕?java binding在点击链接后会自动等待页面加载完毕。
8、selenium的原理是什么?
selenium的原理涉及到3个部分,分别是
- 浏览器
- driver: 一般我们都会下载driver
- client: 也就是我们写的代码
client其实并不知道浏览器是怎么工作的,但是driver知道,在selenium启动以后,driver其实充当了服务器的角色,跟client和浏览器通信,client根据webdriver协议发送请求给driver,driver解析请求,并在浏览器上执行相应的操作,并把执行结果返回给client。这就是selenium工作的大致原理。
9、webdriver的协议是什么?
client与driver之间的约定,无论client是使用java实现还是c#实现,只要通过这个约定,client就可以准确的告诉drier它要做什么以及怎么做。
webdriver协议本身是http协议,数据传输使用json。这里有webdriver协议的所有endpoint,稍微看一眼就知道这些endpoints涵盖了selenium的所有功能。
10、启动浏览器的时候用到的是哪个webdriver协议?
New Session,如果创建成功,返回sessionId和capabilities。
11、什么是page object设计模式?
简单来说就是用class去表示被测页面。在class中定义页面上的元素和一些该页面上专属的方法。
边栏推荐
- 2024. maximum difficulty of the exam - sliding window
- 2022 safety officer-c certificate special operation certificate examination question bank and simulation examination
- Flink passes in custom parameters or profiles
- Xshell startup encountered "unable to continue code execution because mfc110.dll cannot be found"
- 【字符集六】宽字符串和多字节字符互转
- 【无标题】Task3 多路召回
- Visualization of two-dimensional feature logistic regression prediction results
- 128. 最長連續序列-哈希錶
- Minimum transfer times
- 数据库不知道哪里出问题
猜你喜欢

ERROR 1630 (42000): FUNCTION a.avg does not exist. Check the ‘Function Name Parsing and Resolution‘

Implementing architecture caching in MySQL under redis server environment

Technology cloud report: how will the industrial Internet rebuild the security boundary in 2022?

Unittest test framework

node示例后台搭建

Black screen solution for computer boot

Binlog in mysql:

清华大学数据挖掘笔记(一)

The classic dog contract of smart contract (I)
![[character set 9] will GBK be garbled when copied to unicode?](/img/dc/c9ec4a90355d30479f23fdead4b349.png)
[character set 9] will GBK be garbled when copied to unicode?
随机推荐
第七章-更灵活定位内存地址
第三章 寄存器 (内存访问)
Complete knapsack problem 1
Ceil, floor and round functions
(js)三位用逗号隔开,保留两位小数(or 四舍五入取整)
Source code and scheme for target recognition, detection and 6D attitude estimation (the most advanced method and data set)
2024. maximum difficulty of the exam - sliding window
Chapter 3 registers (memory access)
【字符集九】gbk拷贝到Unicode会乱码?
ERROR 1630 (42000): FUNCTION a.avg does not exist. Check the ‘Function Name Parsing and Resolution‘
MySQL learning records -- III. MySQL query statements
2022 simulated examination platform operation of high voltage electrician work license question bank
Top command meaning
Basic knowledge of Linear Algebra -- concepts and relationships of common matrices
Introduction to applet cloud development -- questionnaire evaluation applet practice (7)
Jupyter notebook sets the default browser to open with an error syntaxerror: (Unicode error) 'UTF-8' codec can't decode byte 0xd4
(JS) three digits are separated by commas, and two decimal places are reserved (or rounded)
[sklearn] lightgbm
Technology cloud report: how will the industrial Internet rebuild the security boundary in 2022?
128. longest continuous sequence hash table