如何根据提供的html从菜单中选择选项文件?

2024-05-01 22:05:06 发布

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

我正试着做自动化,在中间打中。 无法从子菜单中选择选项。你知道吗

尝试了堆栈溢出的所有解决方案,但都不起作用。你知道吗

附加代码。你知道吗

<input id="arid_WIN_0_2000053" class="text " readonly="" style="top: 0px; left: 0px; width: 72px; height: 21px;" title="Screen" type="text">

这是我需要单击的id,以便出现一个下拉列表。你知道吗

那是不同的部分,代码是

<table class="MenuTable" style="width: 93px;" cellspacing="0" cellpadding="0">
   <tbody class="MenuTableBody">
      <tr class="MenuTableRow">
         <td class="MenuEntryName" nowrap="">Screen</td>
         <td class="MenuEntryNoSub" arvalue="Screen"></td>
      </tr>
      <tr class="MenuTableRow">
         <td class="MenuEntryName" nowrap="">File</td>
         <td class="MenuEntryNoSub" arvalue="File"></td>
      </tr>
      <tr class="MenuTableRow">
         <td class="MenuEntryName" nowrap="">Printer</td>
         <td class="MenuEntryNoSub" arvalue="Printer"></td>
      </tr>
      <tr class="MenuTableRow">
         <td class="MenuEntryNameHover" nowrap="">(clear)</td>
         <td class="MenuEntryNoSubHover" arvalue=""></td>
      </tr>
   </tbody>
</table>

一旦我选择了IDarid_WIN_0_2000053,我需要选择选项as File。你知道吗

提前谢谢。你知道吗


Tags: 代码textid选项screenwintrclass
2条回答

用作Css定位器:.MenuTableRow:nth-of-type(2) .MenuEntryName

根据HTML从子菜单中选择一个选项,例如文件,您可以使用以下任一解决方案:

driver.find_element_by_xpath("//input[@class='text' and @title='Screen'][starts-with(@id,'arid_WIN_0_')]").click()
driver.find_element_by_xpath("//table[@class='MenuTable']//tr[@class='MenuTableRow']//td[@class='MenuEntryName' and contains(.,'File')]").click()

或者

driver.find_element_by_xpath("//input[@class='text' and @title='Screen'][starts-with(@id,'arid_WIN_0_')]").click()
driver.find_element_by_xpath("//table[@class='MenuTable']//tr[@class='MenuTableRow']//td[@class='MenuEntryNoSub' and @arvalue='File']").click()

相关问题 更多 >