Bug processing HTML tables

7 views
Skip to first unread message

Jesús Martínez

unread,
Jun 22, 2011, 11:21:18 AM6/22/11
to pycc...@googlegroups.com
Hello:

I am using pyccuracy to implement (in a nearly future :) ) and to test my web applications.

I do implement the web application using web2py Framework. And while I wrote test cases I have found a bug.

I don't know if this list is the correct place to comment a bug, but I didn't found a bug tracker to do it. ( I use subversion normally ).


The bug appears when you are getting rows from a html table, using

rows = context.browser_driver.get_table_rows(element_key)

If table has this structure:

<table>
<tbody>
<tr><td /><td /><td /></tr>
<tr><td /><td /><td /></tr>
</tbody>
</table>

you receive all rows correctly.

But if table has this other structure:

<table>
<thead><tr><td /><td /><td /></tr></thead>
<tbody>
<tr><td /><td /><td /></tr>
<tr><td /><td /><td /></tr>
</tbody>
</table>

you receive all rows except the last one.

Well, searching a little :) I have found where to touch the code. And I have played a little.

File: pyccuracy/drivers/core/selenium_driver.py
Function: get_table_rows(self, table_selector)
Line: 275.

Where appears

cell = self.selenium.get_table(table_selector + '.%d.%d' % (

I have

cell = self.selenium.get_table(table_selector + '/tbody/.%d.%d' % (

and now I receive all table's rows except the first one. The code returns all rows under tbody tag.

I know that this change is not the solution. If you wants all rows, and this means ALL rows, this patch forgets the first one.

But I don't know how implement this feature. Can someone help me?

Thanks in advance.

Bernardo Heynemann

unread,
Jun 22, 2011, 12:03:21 PM6/22/11
to pycc...@googlegroups.com
I'll try to check it out soon.

Cheers,
Bernardo Heynemann

2011/6/22 Jesús Martínez <jama...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "pyccuracy" group.
To post to this group, send email to pycc...@googlegroups.com.
To unsubscribe from this group, send email to pyccuracy+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pyccuracy?hl=en.

Jesús Martínez

unread,
Jun 23, 2011, 4:18:19 AM6/23/11
to pycc...@googlegroups.com
Hello:

I have implemented a class inheriting from ActionBase. And I have defined a method that gets rows data from html table which has thead and tbody tags.

It returns all rows under tbody tag as a dict, using the cells in row under thead as keys.

I hope that it will be usefull.

Best regards,


Use:

rows = self.get_table_rows(context.browser_driver,element_key)

Method:

def get_table_rows(self, browser, table_selector):
        # Get index row (keys)
        keys = []
        keys_count = int(browser.get_xpath_count(table_selector + "/thead/tr[1]/th"))

        for keys_index in range(keys_count):
            key = browser.selenium.get_table(table_selector + '/thead.0.%d' % ((keys_index))
            keys.append(key)
        
        # Get rows data
        rows = []
        row_count = int(browser.get_xpath_count(table_selector + "/tbody/tr"))
        
        for row_index in range(row_count):
            row = {}
            cell_count = int(browser.get_xpath_count(table_selector + 
                                                "/tbody/tr[%d]/td" % \
                                                (row_index + 1)))
            for cell_index in range(cell_count):
                cell = browser.selenium.get_table(table_selector + '/tbody.%d.%d' % (
                                                  row_index,
                                                  cell_index
                                                 ))
                row[keys[cell_index]]=cell
            rows.append(row)

        return rows 






2011/6/22 Bernardo Heynemann <heyn...@gmail.com>

Bernardo Heynemann

unread,
Jun 23, 2011, 8:17:15 AM6/23/11
to pycc...@googlegroups.com
Thanks a lot! I'll consider including it in the core code.

Cheers,
Bernardo Heynemann

2011/6/23 Jesús Martínez <jama...@gmail.com>
Reply all
Reply to author
Forward
0 new messages