update: import results check
This commit is contained in:
54
销售订单自动导入.py
54
销售订单自动导入.py
@@ -222,8 +222,8 @@ def main(workbook=None):
|
||||
# 其他错误
|
||||
raise e
|
||||
|
||||
def click(selector, parent=driver, condition=EC.element_to_be_clickable):
|
||||
element = locate(selector, True, parent, condition) if isinstance(selector, str) else selector
|
||||
def click(selector, wait=True, parent=driver, condition=EC.element_to_be_clickable):
|
||||
element = locate(selector, wait, parent, condition) if isinstance(selector, str) else selector
|
||||
counter = lambda: int(element.get_attribute('taximeter') or 0)
|
||||
error = False
|
||||
|
||||
@@ -317,32 +317,39 @@ def main(workbook=None):
|
||||
# 查看导入结果
|
||||
click(".mm-notification-container .mm-icon-close")
|
||||
click(".product-import-img-footer button.mm-button__primary")
|
||||
click(".mm-tbody table tbody tr:nth-child(1) td:nth-child(3) a")
|
||||
driver.switch_to.window(driver.window_handles[2])
|
||||
|
||||
cell = locate(".mm-tbody table tbody tr:nth-child(1) td:nth-child(3)", condition=None)
|
||||
indicator = locate("div > div > span", parent=cell, condition=None)
|
||||
error = int(indicator.text[3:])
|
||||
|
||||
if error != 0:
|
||||
print(f'[警告] {error} 个订单导入失败')
|
||||
print(f'[信息] 提示:可下载失败记录')
|
||||
except Exception as e:
|
||||
print(f'[!!!!] 等待订单录入时发生了错误:{e}')
|
||||
return 84
|
||||
|
||||
try:
|
||||
click("a", wait=False, parent=cell)
|
||||
driver.switch_to.window(driver.window_handles[2])
|
||||
except:
|
||||
print('[!!!!] 查看导入结果时发生了错误')
|
||||
return 85
|
||||
|
||||
ready(driver) #2
|
||||
url = driver.current_url
|
||||
per_page = 5
|
||||
param = f'%22page_size%22%3A{per_page}'
|
||||
|
||||
# 设置每页显示记录数
|
||||
if 'page_size' in url: url = url.replace('%22page_size%22%3A20', param)
|
||||
else: url += param
|
||||
|
||||
driver.get(url)
|
||||
modified = []
|
||||
|
||||
while ready(driver):
|
||||
for idx in range(per_page):
|
||||
try:
|
||||
links = driver.find_elements(By.CSS_SELECTOR, ".list-frame-table .vue-recycle-scroller__item-wrapper .cell[data-cci='1'] a")
|
||||
link = links[idx]
|
||||
except:
|
||||
break
|
||||
# 设置分页选项 10 条/页
|
||||
try:
|
||||
click(".okki-pagination-options-size-changer")
|
||||
click(".okki-select-dropdown .rc-virtual-list-holder-inner div:nth-child(1)")
|
||||
ready(driver)
|
||||
except:
|
||||
print(f'[警告] 分页选项设置失败')
|
||||
pass
|
||||
|
||||
while ready(driver):
|
||||
for link in driver.find_elements(By.CSS_SELECTOR, ".list-frame-table .vue-recycle-scroller__item-wrapper .cell[data-cci='1'] a"):
|
||||
# 编辑订单
|
||||
try:
|
||||
click(link)
|
||||
@@ -378,16 +385,19 @@ def main(workbook=None):
|
||||
driver.close()
|
||||
driver.switch_to.window(driver.window_handles[3])
|
||||
|
||||
click(".component-business-select .mm-selector-rendered")
|
||||
dropdown = locate(".component-business-select .mm-selector-rendered")
|
||||
click(dropdown)
|
||||
|
||||
wait = WebDriverWait(driver, timeout=args.timeout)
|
||||
menu = wait.until(lambda x: x.find_element(By.CSS_SELECTOR, ".mm-outside.mm-select-dropdown"))
|
||||
|
||||
for item in menu.find_elements(By.CSS_SELECTOR, "ul li span"):
|
||||
driver.execute_script("arguments[0].scrollIntoView({ block: 'center' });", item)
|
||||
if item.text.startswith(relation):
|
||||
click(item)
|
||||
associative = True
|
||||
raise KeyboardInterrupt()
|
||||
# 关闭菜单栏
|
||||
click(dropdown)
|
||||
except KeyboardInterrupt:
|
||||
break
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user