问题描述:下拉框选择了某个值去查询,查询后将下拉框复原为默认值,出现了异常提醒。
1、代码及报错
代码
def type_query(self,target_loc,row):
try:
ele_sel = Select(self.find_element(*target_loc))
ele_sel.select_by_index(row)
sleep(0.2)
self.find_element(*self.BaImp_loc).click()
sleep(2)
ele_sel.select_by_index(0)
except BaseException as msg:
print(msg)
报错信息
Message: The element reference of <select id="state" name="state"> is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
2、解决方法
点击查询后,页面被刷新,ele_sel已失效,需要重新获取。
def type_query(self,target_loc,row):
try:
ele_sel = Select(self.find_element(*target_loc))
ele_sel.select_by_index(row)
sleep(0.2)
self.find_element(*self.BaImp_loc).click()
sleep(2)
ele_sel0 = Select(self.find_element(*target_loc))#重新获取
ele_sel0.select_by_index(0)
except BaseException as msg:
print(msg)