python硒选择正确的输入字段
我正在尝试选择正确的输入字段来为其添加一个值。我当前的代码部分有效,它仅选择到第一个输入字段,但我希望能够选择要选择的字段并添加 这是我正在根据值[peterave,sterling等...]选择我的输入字段的Web结构
<tr role="row" class="tester odd">
<td class="hidden"></td>
<td class="hidden">222</td>
<td class="rester-table-cell">
<input type="hidden" name="building[0].model" value="PeterAVE">
<input type="text" name="building[0].size" class="control-input-num">
</td>
<td class="soreted_1" data-search="PeterAVE" data-order="PeterAVE">
<a href="/resilisting/p/PeterAVE">PeterAVE</a>
</td>
</tr>
<tr role="row" class="tester even">
<td class="hidden"></td>
<td class="hidden">333</td>
<td class="rester-table-cell">
<input type="hidden" name="building[1].model" value="Sterling">
<input type="text" name="building[1].size" class="control-input-num">
</td>
<td class="sorted_1" data-search="Sterling" data-order="Sterling">
<a href="/resilisting/p/Sterling">Sterling</a>
</td>
</tr>
,我的代码仅选择并填充Peterave的输入字段,因为这是第一个,并且有数百个我希望能够选择。
这是我使用的代码。
driver.find_element_by_xpath("//input[contains(@class,'control-input-num')] ").send_keys("1")
我非常感谢任何帮助。
I am trying to select the correct input field to add a value to it. My current code partially works and it only selects to the first input field but I want to be able to manage which field I want to select and add
here is what the web structure looks like
<tr role="row" class="tester odd">
<td class="hidden"></td>
<td class="hidden">222</td>
<td class="rester-table-cell">
<input type="hidden" name="building[0].model" value="PeterAVE">
<input type="text" name="building[0].size" class="control-input-num">
</td>
<td class="soreted_1" data-search="PeterAVE" data-order="PeterAVE">
<a href="/resilisting/p/PeterAVE">PeterAVE</a>
</td>
</tr>
<tr role="row" class="tester even">
<td class="hidden"></td>
<td class="hidden">333</td>
<td class="rester-table-cell">
<input type="hidden" name="building[1].model" value="Sterling">
<input type="text" name="building[1].size" class="control-input-num">
</td>
<td class="sorted_1" data-search="Sterling" data-order="Sterling">
<a href="/resilisting/p/Sterling">Sterling</a>
</td>
</tr>
I am selecting my input field based on values [PeterAVE,Sterling, etc...] currently my code is only selecting and filling the input field for PeterAVE since it's the first one and there are hundreds that I want to be able to choose.
Here is the code I am using.
driver.find_element_by_xpath("//input[contains(@class,'control-input-num')] ").send_keys("1")
I really appreciate any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在索引中找到所有输入字段
,然后选择“索引要求”。
您还可以通过先前的隐藏输入的值选择输入字段:
You can find all the input fields with
and then select required by index
You can also select input field by the value of preceding hidden input: