Scrolling to datatable column with selenium

I’m writing some functional tests for my Bokeh app, and in one of them I need to select a particular row of a datatable.

At first I tried getting access to the underlying grid object so I could use grid.scrollRowIntoView() method, but I wasn’t able to. After I found https://discourse.bokeh.org/t/any-way-to-force-datatable-view-to-move-to-a-specific-column, I saw that this is because the grid object is hidden away in Bokeh.index and not in the HTML elements shown.

Since the ColumnDataSource isn’t exposed to the client-side, I can’t use the advice offered in https://discourse.bokeh.org/t/any-way-to-force-datatable-view-to-move-to-a-specific-column to select it.

Is there any way for me to click on a given cell from Selenium?

Here are some of the table-related testing helper functions we use:

1 Like

Thanks! With that help, I was able to figure out a function that would work from the user’s side. The datatable just needs to be given an id in the Jinja template so that it can be found by the css_selector.

def datatableScrollRowIntoView(driver, css_selector, row):
    data_root_id = driver.find_element(By.CSS_SELECTOR, '{} > .bk-root'.format(css_selector)).get_attribute('data-root-id')
    bokeh_view_index_index = driver.execute_script(
        """
            const views = Object.values(Bokeh.index)
            const id = arguments[0]
            for (var i = 0; i < views.length; i++) {
                if (views[i].model.id == id) {
                    return i
                }
            }
        """, data_root_id)
    driver.execute_script(
            'Object.values(Bokeh.index)[arguments[0]].grid.scrollRowIntoView(arguments[1])',
            bokeh_view_index_index, row)
2 Likes