我正在尝试使用python Selenium查找输入框:
try:
thisbox = driver.find_element_by_id('tbRepID')
except EC.NoSuchElementException:
print("Could not locate the Repair ID Box!")
Selenium能够使用相同类型的代码找到前5个框,但由于某些原因,当试图找到第六个框时,它会引发“NoTouchElementException”。我尝试过使用“按名称查找元素”和“按id查找元素”,但没有成功
<table class="gray-border" cellspacing="5" cellpadding="0" width="100%" border="0">
<tbody><tr>
<td colspan="4">
Part Nbr:<input name="tbPn" type="text" id="tbPn" style="width:112px;">
/SN:<input name="tbSn" type="text" id="tbSn" style="width:72px;">
or PO Nbr:<input name="tbPOnbr" type="text" id="tbPOnbr" style="width:72px;">
or SO Nbr:<input name="tbSOnbr" type="text" id="tbSOnbr" style="width:72px;">
or WO Nbr:<input name="tbWOnbr" type="text" id="tbWOnbr" style="width:72px;">
or Rep Id:<input name="tbRepId" type="text" id="tbRepId" style="width:56px;">
<input type="submit" name="bFind1" value="Find" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("bFind1", "", true, "", "", false, false))" id="bFind1">
</td>
</tr>
Tags:
虽然我无法直接引用Rep ID输入框,但我可以使用以下方法间接引用它:
要单击文本或Rep Id的第六个框附件,您需要为
element_to_be_clickable()
导入WebDriverWait,并且可以使用以下任一解决方案:使用
CSS_SELECTOR
:使用
XPATH
:注意:您必须添加以下导入:
如果没有第六个的错误,我真的不知道问题出在哪里
但是通过描述并希望没有代码错误,浏览器可以更改页面的DOM。驱动程序一直试图在错误的DOM中查找元素。 我在一些网页上遇到了这个问题
我对此的解决方案是使用findtheelement与元素进行所有交互。 在Java中:driver.findElement(By.id(“id”))