无法使用Robot Framework向下滚动网页 [英] Unable to scroll down the web page using the Robot Framework
问题描述
我正在使用Selenium 2 Robot Framework来自动化我们的应用程序。我使用下面的JavaScript代码向下滚动页面但无法滚动。
I am using Selenium 2 Robot Framework to automate our application. I have used the below JavaScript code to scroll down the page but am not able to scroll.
我想在向下滚动后在文本框中输入文字,但我是收到例外:
I want to enter text inside the text box after scrolling down, but I am receiving the exception:
元素不可见
Element not visible
默认情况下,文本框在屏幕上部分可见,如果我们手动向下滚动而不是完全可见,但是selenium机器人框架无法向下滚动。
The text box is partially visible on the screen by default, if we manually scroll down than its completely visible, But selenium robot framework unable to scroll down.
我有试过:
Execute JavaScript window.scrollTo(0,200)
Execute JavaScript window.scrollBy(0,200)
Execute JavaScript window.scrollTo(0, document.body.scrollHeight)
有人可以帮我解决这个问题吗?
Can anyone please help me regarding this?
推荐答案
Hey Guys修复了问题执行Javascript $ {element} .scrollby(0,200)
如果元素不在视口中,它将不会在每个情况下都有效。
有效的方法来滚动页面以获取元素以查看端口。
Hey Guys fixed issue Execute Javascript ${element}.scrollby(0,200)
Will not work on every case if element is not in viewport it will not scroll.
there's efficient way to scroll the page to get element to view port .
如果我们使用执行Javascript Window.scroll(x ,y)
我们需要指定水平和垂直位置x,y很难找到并且可能不准确。
If we are using Execute Javascript Window.scroll(x,y)
we need to specify horizontal and vertical position x,y which is difficult to find and may not be accurate .
相反,我们可以使用以下代码行
执行Javascript window.document.evaluate(// xpathlocation,document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue.scrollIntoView(true);
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);
上面的代码将滚动窗口并获取/ xpathlocation中指定的元素以查看端口
The above code will scroll window and get element specified in /xpathlocation to view port
这篇关于无法使用Robot Framework向下滚动网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!