UI自动化测试时遇到的坑

1.创建项目时没有设置Project Interpreter,导致无法运行程序,报错:ModuleNotFoundError: No module named 'selenium'

2.处理分页时,若当前打开的浏览器窗口过小,可能导致仅显示一个分页码,然后定位不到其他的页码

3.无论如何都定位不到元素?

看看元素是不是在frame或者iframe里,用switch_to.frame(类名或id名)定位

4.测试数据(csv文件中)如果格式错误,启动浏览器后会闪退,报错如下:

'utf-8' codec can't decode byte 0xb6 in position 58: invalid start byte

(“utf-8”编解码器无法解码位置58中的字节0xB6:无效的起始字节)

5.为什么if __name__ == '__main__'中的代码没执行?

解决方式如下:https://www.cnblogs.com/youreyebows/p/7867508.html

6.安装文件时,用pip没反应的话,用pip3试试

7. 使用send_keys()方法前需要加上click(),不然输入内容无效且不报错

        send_amount = self.driver.find_element_by_xpath('//*[@class="android.widget.EditText" and @index="0"]')
        send_amount.click()
        send_amount.send_keys("0.00001")

猜测原因:可能是因为前端框架使用的是flutter

8. 无法输入密码(该问题困扰了我好几天,终于解决了,开心😸)

密码框如下:

问题描述:使用send_keys()无法输入内容 

解决方案1:使用pyautogui控制键盘,定位到密码输入框,然后输入密码(密码是:123456)

import pyautogui

pyautogui.PAUSE = 2.5
pyautogui.moveTo(1342, 866, duration=1)
pyautogui.click()
pyautogui.typewrite(['1', '2', '3', '4', '5', '6', 'enter'])
print("测试结束~")

解决方案2:使用appium的tap()方法,针对坐标来定位元素且输入密码

# 关闭没有关闭入口的窗口
    def close_windows(self):
        gs = self.get_windows_size()
        x = 238  # x和y分别代表appium inspector里面的屏幕宽和长
        y = 464
        t = 500
        blank_coordinates = [50, 50]  # 空白处坐标,点击后窗口关闭
        self.driver.tap([(blank_coordinates[0] / x * gs[0], blank_coordinates[1] / y * gs[1])], t)

9. 报错”selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Cannot find any free port in range 8200..8299}. Please set the available port number by providing the systemPort capability or double check the processes that are locking ports within this range and terminate these which are not needed anymore

解决方法:重启模拟器即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值