问题遇到的现象和发生背景
有时候因平台卡顿,导致程序运行出错,需要在程序出错后,忽视错误继续下一次循环
问题相关代码,请勿粘贴截图
driver.find_element_by_xpath('//[@id="app"]/div/div[1]/ul/li[8]/div/span').click() # 中端优化到三方
time.sleep(5)
driver.find_element_by_xpath('//[@id="app"]/div/div[1]/ul/li[8]/ul/li[7]').click() # 地市分析组
time.sleep(5)
df1 = r'C:\Users\liuweiwei\Desktop\工单转派\工单号1.xlsx' # 文件位置
data = xlrd.open_workbook(df1) # 打开文件
sheet1 = data.sheet_by_index(0) # 读取第一个sheet
for lists in range(1, sheet1.nrows): # 从第二行开始遍历
driver.find_element_by_xpath('//[@id="public_inputCompinent__inputMainorderCode"]').send_keys(
sheet1.cell(lists, 1).value) # 从第2列开始逐行读取,
time.sleep(3)
element1 = driver.find_element_by_xpath('//[@id="task_management_mat"]/span') # 搜索
webdriver.ActionChains(driver).move_to_element(element1).click(element1).perform()
driver.implicitly_wait(30)
time.sleep(3)
move1 = driver.find_element_by_xpath(
'// [ @ id = "complex_table__task_out-table"] / div[3] / table / tbody / tr / td[2] / div / div') # 鼠标需悬停元素定位
ActionChains(driver).move_to_element(move1).perform() # 鼠标悬停操作
time.sleep(3)
driver.find_element_by_xpath('//[@ class ="el-dropdown-menu el-popper"] / div[2]/ li ').click() # 任务处理
driver.implicitly_wait(10) # 隐式等待 10s
element = driver.find_element_by_xpath('//[@id="online_task_handle_area"]/button/span') # 定位元素转派处理
time.sleep(3)
element.click() # 点击
print("工单转派成功" + lists)
driver.implicitly_wait(20)
driver.find_element_by_xpath('//[@id="public_inputCompinent__inputMainorderCode"]').clear() # 清空搜索栏
time.sleep(3)
运行结果及报错内容
我的解答思路和尝试过的方法
目前只会手动删除已经遍历的数据,然后重启软件
我想要达到的结果
跳过报错,继续执行下一次循环
```python
driver.find_element_by_xpath('//*[@id="app"]/div/div[1]/ul/li[8]/div/span').click() # 中端优化到三方
time.sleep(5)
driver.find_element_by_xpath('//*[@id="app"]/div/div[1]/ul/li[8]/ul/li[7]').click() # 地市分析组
time.sleep(5)
df1 = r'C:\Users\liuweiwei\Desktop\工单转派\工单号1.xlsx' # 文件位置
data = xlrd.open_workbook(df1) # 打开文件
sheet1 = data.sheet_by_index(0) # 读取第一个sheet
for lists in range(1, sheet1.nrows): # 从第二行开始遍历
driver.find_element_by_xpath('//*[@id="public_inputCompinent__inputMainorderCode"]').send_keys(
sheet1.cell(lists, 1).value) # 从第2列开始逐行读取,
time.sleep(3)
element1 = driver.find_element_by_xpath('//*[@id="task_management_mat"]/span') # 搜索
webdriver.ActionChains(driver).move_to_element(element1).click(element1).perform()
driver.implicitly_wait(30)
time.sleep(3)
move1 = driver.find_element_by_xpath(
'// *[ @ id = "complex_table__task_out-table"] / div[3] / table / tbody / tr / td[2] / div / div') # 鼠标需悬停元素定位
ActionChains(driver).move_to_element(move1).perform() # 鼠标悬停操作
time.sleep(3)
driver.find_element_by_xpath('//*[@ class ="el-dropdown-menu el-popper"] / div[2]/ li ').click() # 任务处理
driver.implicitly_wait(10) # 隐式等待 10s
element = driver.find_element_by_xpath('//*[@id="online_task_handle_area"]/button/span') # 定位元素转派处理
time.sleep(3)
element.click() # 点击
print("工单转派成功" + lists)
driver.implicitly_wait(20)
driver.find_element_by_xpath('//*[@id="public_inputCompinent__inputMainorderCode"]').clear() # 清空搜索栏
time.sleep(3)
```