refactor: improve material code input selection
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.
This commit is contained in:
@@ -152,19 +152,15 @@ class DiscreteMaterialPlanCleaner:
|
|||||||
self._print(f"父容器 .card-table-side-box 已找到")
|
self._print(f"父容器 .card-table-side-box 已找到")
|
||||||
|
|
||||||
|
|
||||||
#page2.pause()
|
page2.pause()
|
||||||
for id in range(detail_count):
|
for id in range(detail_count):
|
||||||
id_lable_locator = child_form.get_by_text("序号 " + str(id + 1))
|
id_lable_locator = child_form.get_by_text("序号 " + str(id + 1))
|
||||||
id_lable_locator.wait_for(state="visible", timeout=10000)
|
id_lable_locator.wait_for(state="visible", timeout=10000)
|
||||||
self._print(f"处理 {id_lable_locator.inner_text()} ")
|
self._print(f"处理 {id_lable_locator.inner_text()} ")
|
||||||
|
|
||||||
# 获取材料编码(使用class精确定位,取第一个非隐藏的input)
|
# 获取材料编码(通过文本定位,取第一个input)
|
||||||
try:
|
input_box = child_form.locator("div").filter(has_text=re.compile(r"^材料编码\d{11}$", re.MULTILINE)).locator("input").first
|
||||||
material_code_input = child_form.locator(".cbmaterialvid").locator("input").first
|
self._print(f"材料编码:{input_box.input_value()}")
|
||||||
material_code = material_code_input.input_value(timeout=5000)
|
|
||||||
self._print(f"材料编码:{material_code}")
|
|
||||||
except Exception as e:
|
|
||||||
self._print(f"材料编码:获取失败 - {e}")
|
|
||||||
|
|
||||||
# 获取材料名称
|
# 获取材料名称
|
||||||
input_box = child_form.locator("div").filter(has_text=re.compile(r"^材料名称$")).locator("input[type='text']")
|
input_box = child_form.locator("div").filter(has_text=re.compile(r"^材料名称$")).locator("input[type='text']")
|
||||||
|
|||||||
Reference in New Issue
Block a user