在Selenium 2 WebDriver(python)中遍历表

wil*_*oup 8 python selenium html-table selenium-webdriver

我在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>
Run Code Online (Sandbox Code Playgroud)

我希望能够使用Selenium 2.0 WebDriver进行迭代,但我找不到任何好的例子.

任何帮助将不胜感激.

wil*_*oup 11

用过的:

from selenium.webdriver.common.by import By

trs = driver.find_elements(By.TAG_NAME, "tr") 

tds = trs[1].find_elements(By.TAG_NAME, "td")
Run Code Online (Sandbox Code Playgroud)

这允许循环遍历每一个以根据需要进行.