From 4b0a882b698e363f81931e22ffccb4476bbe5ed2 Mon Sep 17 00:00:00 2001 From: Misaka_Company Date: Fri, 23 Jan 2026 14:30:35 +0800 Subject: [PATCH] refactor: improve material code input selection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the class-based locator strategy with a text-based filter using regex to accurately identify the material code input field. This change targets elements matching "材料编码" followed by 11 digits, increasing reliability. Also uncommented page2.pause() to assist with debugging the iteration loop. --- utils/离散备料计划维护数据清理.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/utils/离散备料计划维护数据清理.py b/utils/离散备料计划维护数据清理.py index 2898074..65e5d66 100644 --- a/utils/离散备料计划维护数据清理.py +++ b/utils/离散备料计划维护数据清理.py @@ -152,19 +152,15 @@ class DiscreteMaterialPlanCleaner: self._print(f"父容器 .card-table-side-box 已找到") - #page2.pause() + page2.pause() for id in range(detail_count): id_lable_locator = child_form.get_by_text("序号 " + str(id + 1)) id_lable_locator.wait_for(state="visible", timeout=10000) self._print(f"处理 {id_lable_locator.inner_text()} ") - # 获取材料编码(使用class精确定位,取第一个非隐藏的input) - try: - material_code_input = child_form.locator(".cbmaterialvid").locator("input").first - material_code = material_code_input.input_value(timeout=5000) - self._print(f"材料编码:{material_code}") - except Exception as e: - self._print(f"材料编码:获取失败 - {e}") + # 获取材料编码(通过文本定位,取第一个input) + input_box = child_form.locator("div").filter(has_text=re.compile(r"^材料编码\d{11}$", re.MULTILINE)).locator("input").first + self._print(f"材料编码:{input_box.input_value()}") # 获取材料名称 input_box = child_form.locator("div").filter(has_text=re.compile(r"^材料名称$")).locator("input[type='text']")