我有一个包含多个表格的网页,所有表格都有具有类似 TD 的 TR
这是 ObservationStation 表中的按钮
<input type="button" class="gwf-round-button" value="^" onclick="InsertRowBefore('ObservationStations', this, 'TextBox')" title="Add row before">
这是 MeteorlogicalVariables 表中的内容
<input type="button" class="gwf-round-button" value="^" onclick="InsertRowBefore('MeteorologicalVariables', this, 'TextBox')" title="Add row before">
我想要做的是选择 MeteorlogicalVariables 表中第一次出现的按钮并单击它。区分每个表中按钮的唯一标识符是在 onclick 中,我如何访问 MeteorlogicalVariables 表中的第一个按钮?
这是我现在所拥有的:
edit_button = driver.find_element("xpath", '//button[text()="^" and @class="gwf-round-button"][1]')
edit_button.click()
这是 MeteorologicalVariables 表的样子(突出显示的按钮是我想要单击的):
任何帮助解决这个问题的帮助都会很感激
这是特定表格的 HTML,我想单击其中第一次出现的 ^
<table id="MeteorologicalVariables" class="gwf_variable_table">
<colgroup>
<col>
<col style="min-width:150px">
<col style="min-width:200px">
<col style="min-width:200px">
<col style="min-width:200px">
<col style="min-width:220px">
<col style="min-width:220px">
<col style="min-width:275px">
</colgroup>
<tbody>
<tr style="display: table-row;">
<td class="gwf_variable_table_control_column"></td>
<td style="max-width:150px" class="fmc-table-label-font fmc-tb-height">Variable</td>
<td style="max-width:200px" class="fmc-table-label-font fmc-tb-height">Station Name</td>
<td style="max-width:200px" class="fmc-table-label-font fmc-tb-height">Sensor(s)</td>
<td style="max-width:200px" class="fmc-table-label-font fmc-tb-height">Height / Depth (m)</td>
<td style="max-width:220px" class="fmc-table-label-font fmc-tb-height">Record Period</td>
<td style="max-width:220px" class="fmc-table-label-font fmc-tb-height">Measurement Frequency</td>
<td style="max-width:275px" class="fmc-table-label-font fmc-tb-height">Notes / Details</td>
</tr>
<tr>
<td class="gwf_variable_table_control_column">
<div class="gwf_tooltip"><input type="button" class="gwf-round-button" value="^" onclick="InsertRowBefore('MeteorologicalVariables', this, 'TextBox')" title="Add row before"></div>
<div class="gwf_tooltip"><input type="button" class="gwf-round-button" value="X" onclick="DeleteRow('MeteorologicalVariables', this)" title="Delete current row"></div>
<div class="gwf_tooltip"><input type="button" class="gwf-round-button" value="v" onclick="InsertRowAfter('MeteorologicalVariables', this, 'TextBox')" title="Add row after"></div>
</td>
<td><input type="text" class="fmc-tb-appearance fmc-tb-font fmc-tb-height" style="width:100%"></td>
<td><textarea class="fmc-tb-appearance fmc-tb-font" style="height:60px;min-width:200px;width:200px;max-width:200px;"></textarea></td>
<td><textarea class="fmc-tb-appearance fmc-tb-font" style="height:60px;min-width:200px;width:200px;max-width:200px;"></textarea></td>
<td><input type="text" class="fmc-tb-appearance fmc-tb-font fmc-tb-height" style="width:100%"></td>
<td><input type="text" class="fmc-tb-appearance fmc-tb-font fmc-tb-height" style="width:100%"></td>
<td><input type="text" class="fmc-tb-appearance fmc-tb-font fmc-tb-height" style="width:100%"></td>
<td><textarea class="fmc-tb-appearance fmc-tb-font" style="height:60px;min-width:275px;width:275px;max-width:275px;"></textarea></td>
</tr>
<tr>
<td class="gwf_variable_table_control_column">
<div class="gwf_tooltip"><input type="button" class="gwf-round-button" value="^" onclick="InsertRowBefore('MeteorologicalVariables', this, 'TextBox')" title="Add row before"></div>
<div class="gwf_tooltip"><input type="button" class="gwf-round-button" value="X" onclick="DeleteRow('MeteorologicalVariables', this)" title="Delete current row"></div>
<div class="gwf_tooltip"><input type="button" class="gwf-round-button" value="v" onclick="InsertRowAfter('MeteorologicalVariables', this, 'TextBox')" title="Add row after"></div>
</td>
<td><input type="text" class="fmc-tb-appearance fmc-tb-font fmc-tb-height" style="width:100%"></td>
<td><textarea class="fmc-tb-appearance fmc-tb-font" style="height:60px;min-width:200px;width:200px;max-width:200px;"></textarea></td>
<td><textarea class="fmc-tb-appearance fmc-tb-font" style="height:60px;min-width:200px;width:200px;max-width:200px;"></textarea></td>
<td><input type="text" class="fmc-tb-appearance fmc-tb-font fmc-tb-height" style="width:100%"></td>
<td><input type="text" class="fmc-tb-appearance fmc-tb-font fmc-tb-height" style="width:100%"></td>
<td><input type="text" class="fmc-tb-appearance fmc-tb-font fmc-tb-height" style="width:100%"></td>
<td><textarea class="fmc-tb-appearance fmc-tb-font" style="height:60px;min-width:275px;width:275px;max-width:275px;"></textarea></td>
</tr>
你
XPath
错了,看起来没有文字=^
尝试一下
XPath
:通过:
有多种方法可以做到这一点,例如。
严格遵循 HTML 的结构:
input
即,在MeteorlogicalVariables 的div
第一个中选择td
第二个。tr
table
生成一个符合某些约束的序列并从中取出第一个:
^
即在 MeteorlogicalVariables 中选择第一个值为的“输入”table