Selenium Python检查是否需要字段

2024-09-26 22:42:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要检查哪些字段是必需的,并提取字段的名称(innerText)

在这个例子中,我需要得到“监督组织”和“工人类型”。然而,“WOEG-WBEG-WAFG”也用于非必填字段,因此我需要依赖“WMEG-WHGG”类类型。 enter image description here

<li class="WMEG WHGG" role="presentation" data-automation-id="formLabelRequired">
   <div class="WOEG WBEG WAFG">
      <label id="56$565285--uid6-formLabel" data-automation-id="formLabel" for="56$565285--uid6-input">Supervisory Organization</label>
<li class="WMEG WHGG" role="presentation" data-automation-id="formLabelRequired">
   <div class="WOEG WBEG WAFG">
      <label id="56$565284-input--uid11-input-formLabel" data-automation-id="formLabel" for="56$565284-input--uid11-input">Worker Type</label>

提前谢谢


Tags: id类型inputdatalilabelclassrole
1条回答
网友
1楼 · 发布于 2024-09-26 22:42:21

看看这是否有帮助

listItems = driver.find_elements_by_tag_name("li")
for e in listItems:
    isRequired = e.get_attribute("data-automation-id")
    if isRequired!="" and "Required" in isRequired:
        print(e.find_element_by_xpath(".//div/label").text)

相关问题 更多 >

    热门问题