我如何遍历表格并打印出Selenium Webdriver Python列的值

里亚兹·拉达尼(Riaz Ladhani)

我在遍历html表并从每一行的第2列输出值时遇到问题。第1行中td [2]的第2列具有值“名称”,第2行中第2列具有值“地址”,依此类推。我正在尝试将值打印到控制台。

我的Python网络驱动程序代码为:

    # Get the table
table_xpath = self.driver.find_element(By.XPATH, 'html/body/div[2]/div[2]/div/div[4]/div/div[2]/div/div[3]/div/div[5]/div/div[3]/div/div[4]/div/div[2]/div/div[4]/div/div[3]/div/div[2]/div/div/table/tbody')
# Get the rows from the table
rows = table_xpath.find_elements(By.TAG_NAME, "tr.GAT4PNUFG.GAT4PNUMG")
# Get the columns (all the column 2)
cols = rows.find_elements(By.TAG_NAME, "td")[2]
for i in cols:
    print cols.text

我得到的错误是:

  File "C:\Webdriver\ClearCore 501\Pages\data_objects_saved_page.py", line 87, in verify_variables_created
cols = rows.find_elements(By.TAG_NAME, "td")[2]

AttributeError:“列表”对象没有属性“ find_elements”

HTML代码段是:

     <table cellspacing="0" style="table-layout: fixed; width: 100%;">
    <colgroup>
    <tbody>
        <tr class="GAT4PNUFG GAT4PNUMG" __gwt_subrow="0" __gwt_row="0">
            <td class="GAT4PNUEG GAT4PNUGG GAT4PNUHG GAT4PNUNG">
            <td class="GAT4PNUEG GAT4PNUGG GAT4PNUNG">
                <div __gwt_cell="cell-gwt-uid-324" style="outline-style:none;">
                    <span class="linkhover" title="Name" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">Name</span>
                </div>
            </td>
            <td class="GAT4PNUEG GAT4PNUGG GAT4PNUNG">
            <td class="GAT4PNUEG GAT4PNUGG GAT4PNUNG">
            <td class="GAT4PNUEG GAT4PNUGG GAT4PNUNG">
            <td class="GAT4PNUEG GAT4PNUGG GAT4PNUBH GAT4PNUNG">
        </tr>
        <tr class="GAT4PNUEH" __gwt_subrow="0" __gwt_row="1">
            <td class="GAT4PNUEG GAT4PNUFH GAT4PNUHG">
            <td class="GAT4PNUEG GAT4PNUFH">
                <div __gwt_cell="cell-gwt-uid-324" style="outline-style:none;">
                    <span class="linkhover" title="Address" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">Address</span>
                </div>
            </td>
            <td class="GAT4PNUEG GAT4PNUFH">
            <td class="GAT4PNUEG GAT4PNUFH">
            <td class="GAT4PNUEG GAT4PNUFH">
            <td class="GAT4PNUEG GAT4PNUFH GAT4PNUBH">
        </tr>
        <tr class="GAT4PNUFG" __gwt_subrow="0" __gwt_row="2">
            <td class="GAT4PNUEG GAT4PNUGG GAT4PNUHG">
            <td class="GAT4PNUEG GAT4PNUGG">
                <div __gwt_cell="cell-gwt-uid-324" style="outline-style:none;">
                    <span class="linkhover" title="DOB" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">DOB</span>
                </div>
            </td>
            <td class="GAT4PNUEG GAT4PNUGG">
            <td class="GAT4PNUEG GAT4PNUGG">
            <td class="GAT4PNUEG GAT4PNUGG">
            <td class="GAT4PNUEG GAT4PNUGG GAT4PNUBH">
        </tr>
        <tr class="GAT4PNUEH" __gwt_subrow="0" __gwt_row="3">
            ---
        <tr class="GAT4PNUFG" __gwt_subrow="0" __gwt_row="4">       
            ---
    </tbody>
</table>

我如何遍历该表并打印Python中的值,请使用Webdriver?

里亚兹·拉达尼(Riaz Ladhani)

开发人员已将ID放入表格中。我现在正在工作。它正在打印第2列中的所有单元格值。代码是:

table_id = self.driver.find_element(By.ID, 'data_configuration_feeds_ct_fields_body0')
rows = table_id.find_elements(By.TAG_NAME, "tr") # get all of the rows in the table
    for row in rows:
    # Get the columns (all the column 2)        
    col = row.find_elements(By.TAG_NAME, "td")[1] #note: index start from 0, 1 is col 2
    print col.text

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何使用Selenium WebDriver打印<nobr>标记中存在的值

来自分类Dev

Selenium Webdriver Python,无法按值查找?

来自分类Dev

使用Selenium Webdriver,Python检索动态值

来自分类Dev

Selenium Webdriver Python,无法按值查找?

来自分类Dev

Python Selenium Webdriver:调试

来自分类Dev

StaleElementReferenceException Selenium WebDriver Python

来自分类Dev

Selenium Webdriver Python storeTextPresent

来自分类Dev

Selenium Webdriver获得Cookie值

来自分类Dev

Python,Selenium Webdriver:如何找到此属性的值?

来自分类Dev

Selenium WebDriver Python,搜索WebElement

来自分类Dev

Python Selenium:处理Webdriver异常

来自分类Dev

Selenium Webdriver 获取元素(Python)

来自分类Dev

Python Selenium webdriver超时异常

来自分类Dev

如何获取早期版本的Python Selenium Webdriver

来自分类Dev

Selenium WebDriver元素遍历

来自分类Dev

使用Python Selenium WebDriver处理异常的返回值

来自分类Dev

无法使用WebDriver Python Selenium设置组合框的下拉值

来自分类Dev

Python 使用 selenium webdriver 获取元素的 CSS 颜色值

来自分类Dev

如何使用 selenium webdriver 读取表格中的单元格值

来自分类Dev

Selenium Python Webdriver chrome打印所有img的src

来自分类Dev

如何在python中使用webdriver选择下拉列表值

来自分类Dev

Selenium Webdriver上的超时默认值

来自分类Dev

使用Selenium Webdriver设置WebElement的div值

来自分类Dev

使用 selenium webdriver 时如何从列中获取特定值并将其插入字段中

来自分类Dev

Selenium Python使用get_attribute('value')打印出textfield的值不打印该值。我要打印空白

来自分类Dev

如何使用Selenium WebDriver获取Vue对象的值?

来自分类Dev

如何验证Selenium Webdriver 2中下拉值的顺序?

来自分类Dev

如何使用Selenium WebDriver捕获SVG图像的工具提示值?

来自分类Dev

如何从Selenium WebDriver中的表数据获取列表项值?

Related 相关文章

  1. 1

    如何使用Selenium WebDriver打印<nobr>标记中存在的值

  2. 2

    Selenium Webdriver Python,无法按值查找?

  3. 3

    使用Selenium Webdriver,Python检索动态值

  4. 4

    Selenium Webdriver Python,无法按值查找?

  5. 5

    Python Selenium Webdriver:调试

  6. 6

    StaleElementReferenceException Selenium WebDriver Python

  7. 7

    Selenium Webdriver Python storeTextPresent

  8. 8

    Selenium Webdriver获得Cookie值

  9. 9

    Python,Selenium Webdriver:如何找到此属性的值?

  10. 10

    Selenium WebDriver Python,搜索WebElement

  11. 11

    Python Selenium:处理Webdriver异常

  12. 12

    Selenium Webdriver 获取元素(Python)

  13. 13

    Python Selenium webdriver超时异常

  14. 14

    如何获取早期版本的Python Selenium Webdriver

  15. 15

    Selenium WebDriver元素遍历

  16. 16

    使用Python Selenium WebDriver处理异常的返回值

  17. 17

    无法使用WebDriver Python Selenium设置组合框的下拉值

  18. 18

    Python 使用 selenium webdriver 获取元素的 CSS 颜色值

  19. 19

    如何使用 selenium webdriver 读取表格中的单元格值

  20. 20

    Selenium Python Webdriver chrome打印所有img的src

  21. 21

    如何在python中使用webdriver选择下拉列表值

  22. 22

    Selenium Webdriver上的超时默认值

  23. 23

    使用Selenium Webdriver设置WebElement的div值

  24. 24

    使用 selenium webdriver 时如何从列中获取特定值并将其插入字段中

  25. 25

    Selenium Python使用get_attribute('value')打印出textfield的值不打印该值。我要打印空白

  26. 26

    如何使用Selenium WebDriver获取Vue对象的值?

  27. 27

    如何验证Selenium Webdriver 2中下拉值的顺序?

  28. 28

    如何使用Selenium WebDriver捕获SVG图像的工具提示值?

  29. 29

    如何从Selenium WebDriver中的表数据获取列表项值?

热门标签

归档