selenium自动化脚本错误总结

本文列举并解析了在使用Selenium进行自动化测试时常见的错误,包括元素不可点击、Alert异常处理、驱动未安装等问题,并提供了相应的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

编写selenium脚本时,会犯些错误,纪录下来,方便自己后续查看

1、定位元素时提示:

unknown error: Element is not clickable at point (580, 47). Other element would receive the click: <label for="stb_1">...</label>

提示:元素无法点击,其他的元素会接收此点击行为。
分析原因,首先肯定不是因为页面元素不存在而无法点击。
分析后得出,实际上这个页面元素是存在的,而是被另外一个弹层挡住了。

2、
selenium.common.exceptions.NoAlertPresentException: Message: no alert open
提示没有alert弹框弹出,分析得出是因为前面有个元素没有定位到,但是为什么不直接提示元素没有定位到,而是提示没有alert弹出。。。

3、
alert = driver.switch_to.alert()
TypeError: 'Alert' object is not callable

对象不能用函数形式调用,就是不能callable。 此类错误一般是由于内部函数被用作变量名时发生

4、

selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

没有安装火狐浏览器的驱动,我安装环境时,只安装了chrome的驱动,安装firefox的驱动即可

5、

driver.find_element_by_id("su").click()
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Element is not clickable at point (611, 28)
  (Session info: chrome=54.0.2840.71)
  (Driver info: chromedriver=2.25.426935 (820a95b0b81d33e42712f9198c215f703412e1a1),platform=Mac OS X 10.11.5 x86_64)

因为在程序中使用了set_window_size设置了窗口的大小,窗口缩小后,导致某个元素无法点击;
解决办法:将set_window_size设置的宽度调大,使driver.find_element_by_id(“su”).click()被定位的元素不被遮挡即可。

6、

    tagname1 = root.getElementByTagName('browser')
AttributeError: 'Element' object has no attribute 'getElementByTagName'

在定位元素过程中,注意当获取一组标签时,element是复数,改为tagname1 = root.getElementsByTagName(‘browser’)即可;

7、

    raise ImportError('Start directory is not importable: %r' % start_dir)
ImportError: Start directory is not importable: './tesCase/'

这个错误很低级,然后自己还找了好久,记录一下,路径写错了,’./testCase/’,少了一个字母t

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

猜不透987872674

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值