我是 Python 新手,我正在尝试单击具有 HTML 结构的以下按钮:
<div class="buttons">
<input name="ctl00$cphMain$mscSeats$tabStatus$btnDeviceMissingModal" value="Dispositivo" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$cphMain$mscSeats$tabStatus$btnDeviceMissingModal", "", true, "", "", false, false))" id="cphMain_mscSeats_tabStatus_btnDeviceMissingModal" class="modal btnRed border-radius cboxElement" href="#pnlReportMissingConfirm" type="submit">
</div>
我尝试使用以下代码:
element = driver.find_element_by_xpath("//input[@name='ctl00$cphMain$mscSeats$tabStatus$btnDeviceMissingModal']")
element.click()
为避免在查找元素时出现计时问题,建议使用诸如 Wait 或 FluentWait 之类的 selenium 类。FluentWait 查找元素,如果没有找到,它会每隔 x 次查找它,您指定的时间最长为 y。
例如,在您的情况下,它将每秒获取输入 10 秒。这样您就不必根据每次需要多长时间来修改睡眠。
我将 java 用于 selenium,它看起来像这样,以搜索可点击元素,例如: