Search code examples
pythonseleniumcounthtml-tablelines

Selenium number of lines in a table?


I have this structure :

<table>
<tbody>
    <tr id="1_2011_11_11_07_45_00" class="on">
    </tr>
    <tr id="1_2011_11_11_09_25_00">
    </tr>
    <tr id="1_2011_11_11_11_05_00">
    </tr>
    <tr id="1_2011_11_11_14_50_00">
    </tr>
    <tr id="1_2011_11_11_16_00_00">
    </tr>
    <tr id="1_2011_11_11_18_10_00">
    </tr>
    <tr id="1_2011_11_11_21_30_00">
    </tr>
</tbody>

and I would like to count the number of lines that are in the table. I am using Python for the script. The xpath of the table is :

xpath=/html/body/form/div[3]/div/div/div[2]/div/div/table

Anyone could help me ?


Solution

  • Can also be done via get_xpath_count. for ex. Number_of_row = $browser.get_xpath_count("/tbody/tr")

    I have not checked the above code but I think it will work