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



我正在尝试自动化,并在中间罢工。 无法从子菜单中选择选项。

尝试了堆栈溢出的所有解决方案,但一切都不起作用。

附加代码。

<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后,我需要选择选项作为文件。

提前谢谢。

根据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()

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

最新更新