我在 HTML 中有以下表格布局(相应更改):
<table class="other-table-style">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
</tr>
<tr>
<td align="center" width="30%">Joe</td>
<td align="center" width="30%">Bloggs</td>
<td align="center" width="40%">28</td>
</tr>
<tr>
<td align="center" width="30%">John</td>
<td align="center" width="30%">Doe</td>
<td align="center" width="40%">30</td>
</tr>
</table>
我希望能够使用 Selenium 2.0 WebDriver 对此进行迭代,但我找不到任何好的示例。
如有任何帮助,我们将不胜感激。
最佳答案
用过的:
from selenium.webdriver.common.by import By
trs = driver.find_elements(By.TAG_NAME, "tr")
tds = trs[1].find_elements(By.TAG_NAME, "td")
这允许循环遍历每一个以根据需要进行操作。
关于python - 遍历 Selenium 2 WebDriver 中的表(python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12057118/