seleniumrobotframeworkselenium2library

scroll until the element is in view using Selenium2Library Keyword


I am using Robot Framework for my web application automation execution.I had found one such solution using Selenium Web-driver.

scroll until the element is in view using Selenium Webdriver

But I wanted to accomplish this using Robotframewrok-Selenium2Library.

Please suggest such keyword if any.

Thanks.


Solution

  • Because I can not install ExtendedSelenium2Library package, I use Execute JavaScript to run javascript directly:

    *** Keywords ****
    
    Add Your Methods
        ${YourElement}=    Get WebElement   ${YourElementXpath}
        Execute JavaScript    arguments[0].scrollIntoView(false);    ARGUMENTS   ${YourElement}
    
        Wait Until Element is visible    ${YourElement}     timeout=5s
        Set Focus To Element    ${YourElement}    
        Click Element    ${YourElement}
    

    The javascript

    arguments[0].scrollIntoView(false);
    

    scroll your element in to browser viewport.