Unable to scroll down the web page using the Robot Framework

六眼飞鱼酱① 提交于 2019-12-03 08:47:19

Your scrolling code looks ok. However, I don't think scrolling is your problem. Element visibility is ok even if it is scrolled away from screen. Try this code for example. At least on Chrome page scrolls back up at Input Text keyword

*** Settings ***
Library         Selenium2Library

*** Test Cases ***
Scroll
    Open Browser   http://www.stackoverflow.com/    Chrome
    Execute JavaScript    window.scrollTo(0, document.body.scrollHeight)
    Input Text    //*[@id="search"]/input    robot framework
    Sleep    3
    Close All Browsers

I think you may have an incorrect locator for your edit box.

Tibin Geo k k

I fixed the issue with Execute JavaScript ${element}.scrollby(0,200). It will not work in every case. If the element is not in a viewport it will not scroll.

There's an efficient way to scroll the page to get the element to a view port.

If we are using Execute JavaScript Window.scroll(x,y), we need to specify a horizontal and vertical position, x,y, which is difficult to find and may not be accurate.

Instead we can use the following line of code, Execute JavaScript window.document.evaluate("//xpathlocation", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.scrollIntoView(true);

The above code will scroll the window and get the element specified in /xpathlocation to the view port.

ofarooq

You can use this as a keyword:

Execute Javascript    $(document).scrollTop(${x})

Where,

x is the number in milliseconds to scroll down.

feiyuw

Have you tried in Selenium webdriver in the IPython console directly?

I have tried as in the following, and it is able to scroll down.

from selenium import webdriver
firefox = webdriver.Firefox()
firefox.get('http://twitter.com')
firefox.execute_script('window.scrollTo(0,200)')
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!