Scroll down pages into bottom in Django Lettuce Selenium


The most common things happen when we have long pages is the element’s is not found or not clickable.

1
2
3
4
5
6
7
8
Traceback (most recent call last):
      File "/home/yodi/.virtualenvs/insurance/lib/python2.7/site-packages/lettuce/core.py", line 143, in __call__
        ret = self.function(self.step, *args, **kw)
      File "/home/yodi/web/insurance/../insurance/tests/step_definitions/web_steps.py", line 63, in i_press
        world.browser.find_by_xpath(‘//button[text()="%s"]’ % value).click()
      File "/home/yodi/.virtualenvs/insurance/lib/python2.7/site-packages/splinter/element_list.py", line 67, in __getattr__
        raise AttributeError("’%s’ object has no attribute ‘%s’" % (self.__class__.__name__, name))
    AttributeError: ‘ElementList’ object has no attribute ‘click’

To solve this problem, we can execute scroll down by :

1
2
3
@step("I scroll down")
def i_scroll_down(step):
    world.browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.