'Scraping all tbody tags in table using selenium in python
I tried to get all tbody tags in table and click on each. When I do iteration by using command below, I find them all by storing in the list, then I iterate over them and click on each. When I try to click I get error: stale element reference: element is not attached to the page document
WebDriverWait(self._browser, 15).until( EC.visibility_of_all_elements_located((By.CLASS_NAME, 'exactMatch')))
I think that while I store all found tbody tags in list, the page might be updated and links in the list are not relevant. So I tried to click on each tbody tag once I find it using index. But my code doesnt work:
numberOfRows = len(WebDriverWait(self._browser, 15).until(
EC.visibility_of_all_elements_located((By.CLASS_NAME, 'exactMatch'))))
for iRow in range(numberOfRows):
currentRow = WebDriverWait(self._browser, 5).until(EC.presence_of_element_located(
(By.XPATH, "(//table[@id='searchResultsTable']/tbody[" + str(iRow + 1) + "]")))
currentRow.click()
Example of HTML:
<table class="searchResultsTable" ng-class="{searchIsStopped: ctrl.isSearchStopped()}" cellspacing="0">
<tbody class="resultItem exactMatch">
<tr id="LS4KvUFe" class="qa-match-row resultSummary unread">
<td class="new"> </td> </tr>
</tbody>
<tbody class="resultItem exactMatch">
<tr id="LS4KvUFd" class="qa-match-row resultSummary unread">
<td class="new"> </td> </tr>
</tbody>
</table>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
