Selenium常见异常,如:selenium.common.exceptions.StaleElementReferenceException

今天写脚本的时候,报错selenium.common.exceptions.StaleElementReferenceException,一个参考的元素现在是“过时”时抛出异常。 “过时”是指这个元素不再出现在页面的Dom中。
原因是,因为表格中数据有变化时,页面会自动刷新,导致找不到元素
解决办法:使用try……except语句重新获取元素
在脚本中导入exceptions,如下语句:

from selenium.common import exceptions as ex

try:
	xxxxxxxxxx
except ex.StaleElementReferenceException:
	xxxxxxxxx

找到一篇文章,总结了selenium中常见的异常,转载如下:
https://www.cnblogs.com/liuye1990/p/10142610.html

你可能感兴趣的:(selenium,selenium)