python - 遍历 Selenium 2 WebDriver 中的表(python)

标签 python selenium selenium-webdriver html-table

我在 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/

相关文章:

python - 有什么方法可以告诉 selenium 在某个时候不要执行 js?

java - 在 selenium webdriver 中,当我添加参数并运行下面的程序时,显示错误

python - 无法在 Windows 上安装 python lxml(和 libxml2)

python - 如何使 Selenium WebDriver 不等待整个页面加载

Python jsonschema 不标记日期时间错误

java - Maven 运行 testNG 套件两次

Selenium RC verifyTrue(selenium.isTextPresent (“string” ))

java - Selenium 无法定位 html 页面中的任何元素

javascript - 订单 Protractor/webdriver 执行 promise

java - Python 相当于 java ObjectOutputStream 和 ObjectInputStream?