用selenium自动填充网页表格时,有两个附件需要上传,附件大小不同,网速有快慢,所以上传时间不确定(目前简单设置了15s休眠),这就导致了在上传第2个附件时,有时候会出现因第一个附件还在上传中网页冻结状态下,无法点击第二个上传按钮,发生报错。
如何才能设置自动等待第一个上传结束,再无缝衔接上第二个的上传。
app = Application()
# 定位到窗口
app = app.connect(title_re='打开', class_name='#32770')
# 在输入框输入文件位置
app['打开']['Edit1'].set_edit_text(file_path)
# 点击打开,上传文件
app['打开']['Button1'].click_input()
time.sleep(15)
# 添付检查清单,如果有的话
if checklist_name in allItems:
# WebDriverWait(driver,5, 0.5).until(EC.invisibility_of_element_located((By.CLASS_NAME, "FreezePaneOn")))
# WebDriverWait(driver,60,0.5).until(EC.element_to_be_clickable((By.CLASS_NAME, element)))
driver.find_elements(By.CLASS_NAME, 'dz-span')[1].click()
time.sleep(5)
app = Application()
# 定位到窗口
app = app.connect(title_re='打开', class_name='#32770')
# 在输入框输入文件位置
app['打开']['Edit1'].set_edit_text(checklist_path)
# 点击打开,上传文件
app['打开']['Button1'].click_input()
time.sleep(8)
报错内容如下
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <span class="dz-span" id="dz_message_span_i10200_10771_sTKHovNakX">...</span> is not clickable at point (1005, 858). Other element would receive the click: <div align="center" id="FreezePane" class="FreezePaneOn" style="height: 4398px; width: 1848px;">...</div>
1秒获取一次第二个按钮的状态,若可用则第一个上传完了