Selenium WebDriver Java Framework Course Limited Time Offer for $20

Selenium WebDriver Java Framework Course Limited Time Offer for $20

 

Print

Page Scroll Using Robot Framework Python

When using Robot Framework to test web application, sometimes, robot needs to scroll page to a location to display web elements or to do other operations. We can achieve scroll page by using keywords "Execute JavaScript window.scrollTo(x,y)".  See the example below.

 

Note: in this example, I created a custom keywords "Scroll Page To Location" with two arguments "${x_location} and ${y_location}".  I use the keyword in the ScrollPage test case under Robot Example Suite.

create a robot project as shown below.

ScrollPage Test Case Step:

Text View Image

Text View

*** Settings ***
Library           Selenium2Library

*** Test Cases ***
Scroll Page
    Open Browser    http://demo.mahara.org    firefox
    Maximize Browser Window
    Sleep    5s
    Scroll Page To Location    0    2000

*** Keywords ***
Scroll Page To Location
    [Arguments]    ${x_location}    ${y_location}
    Execute JavaScript    window.scrollTo(${x_location},${y_location})

Run the test and observer the result. The test passed. In this script, Sleep 5s is for you to observe the page scroll, so in actual test framework, you can remove that step.