ScrollIntoView () scrolls heavily

I have a test in selenium (using Python and FirefoxWebdriver). On the test site, I have a table of records, and I want to click an element in this table, but I need to scroll through this element, and then I can click on it.

To scroll, I use this method:

def scroll_to_element(self, element):
    try:
        self.driver.execute_script("return arguments[0].scrollIntoView();", element)

    except Exception as e:
        print 'error scrolling down web element', e

But this method scrolls a lot. The item is on about 2 lines from the top and is still not visible. Is there any other way that scrolls an Element? I do not experience these scenarios at all.

Here is the table:

<table id="idMainGriddata_columns" agname="data_columns" userid="1" entityidcolumnname="dc_id" editable="1" border="0" class="adodb_dbgrid" scrollx="0">
    <colgroup>
        <col width="25">
        # ...
    </colgroup>
    <tbody>
        <tr entityid="14" class="adodb_dbgrid_even_row">
            <td class="centered" value="14">...</td>
            # ...
        </tr>
        # ... 400x tr
    </tbody>
</table>

and this method is used here:

variable = driver.find_element_by_xpath("//table[@id='idMainGriddata_columns']/tbody/tr/td[contains(text(), '" + column + "')]")
st.scroll_to_element(self, variable)
actions = ActionChains(self.driver)
actions.move_to_element(variable)
actions.double_click(variable)
actions.perform()
+4
source share
1 answer

Solution 1

, :

driver.find_element_by_xpath("//table[@id='idMainGriddata_columns']/tbody/tr/td[contains(text(), '" + column + "')]").click()

Js , .

2 ( )

:

column += 2

3

alignToTop scrollIntoView:

self.driver.execute_script("return arguments[0].scrollIntoView(true);", element)
+4

Source: https://habr.com/ru/post/1614698/


All Articles