Мне нужно нажать на элемент с текстом как C1111-8PLTELAWZ в TR.Когда я использовал XPath "xpath("//table[@id='tbl']/tbody/tr[2]/td[2]").click()"
, `сталкивался с ошибкой ниже:
Traceback (most recent call last):
File "acs.py", line 17, in <module>
qwe = browser.find_element_by_xpath("//table[@id='tbl']/tbody/tr[2]/td[2]").click()
File "/users/hemgr/selenium/webdriver/remote/webdriver.py", line 394, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "/users/hemgr/selenium/webdriver/remote/webdriver.py", line 978, in find_element
'value': value})['value']
File "/users/hemgr/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/users/hemgr/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //table[@id='tbl']/tbody/tr[2]/td[2]
Код HTML:
<span id="UpdatePanel1">
<table id="tbl" class="device_settings" x-ms-format-detection="none" style="width:100%;border-collapse:collapse;" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<th class="cell_header" style="width:20px;"><input type="checkbox" onclick="CheckAllRows(this);" id="IsCheckAllRows"></th>
<th class="cell_header" onclick="SetOrder( 'manufacturer_name')" style="CURSOR:pointer;"><span style="text-decoration:underline;">Manufacturer</span></th>
<th class="cell_header" onclick="SetOrder( 'product_class_model')" style="CURSOR:pointer;"><span style="text-decoration:underline;">Model name</span></th>
<th class="cell_header" onclick="SetOrder( 'device_serial')" style="CURSOR:pointer;"><span style="text-decoration:underline;">Serial</span></th>
<th class="cell_header" onclick="SetOrder( 'device_created')" style="CURSOR:pointer;"><span style="text-decoration:underline;">Created</span></th>
<th class="cell_header" onclick="SetOrder( 'device_updated')" style="CURSOR:pointer;"><span style="text-decoration:underline;">Updated</span><img src="../Images/down.gif"></th>
<th class="cell_header_a" onclick="SetOrder( 'device_status')" style="CURSOR:pointer;"><span style="text-decoration:underline;">Status</span></th>
</tr>
<tr isactive="Ok" rowid="9" onmouseout="RowOut(this, event)" onmouseover="RowOver(this, event);" onclick="RowClick('9',event);" style="cursor:pointer;">
<td class="cell_inactive_item" onclick="CheckRow(this, event);" style="width:20px;cursor:default;" align="center"><input type="checkbox" onclick="CheckRow(this, event);"></td>
<td class="cell_inactive_item" align="center">Cisco Systems Inc</td>
<td class="cell_inactive_item" align="center">C1117-4PLTEEA</td>
<td class="cell_inactive_item" align="center">FGL212891Z6</td>
<td class="cell_inactive_item" align="center"><span style="white-space:nowrap;">2/15/2019 11:37:14</span></td>
<td class="cell_inactive_item" align="center"><span style="white-space:nowrap;">2/15/2019 14:12:50</span></td>
<td class="cell_inactive_item_a" align="center">0</td>
</tr>
</table>
</span>