Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrolling page in RSelenium

How can I manually scroll to the bottom (or top) of a page with the RSelenium WebDriver? I have an element that only becomes available when it is visible on the page.

like image 653
hfisch Avatar asked Aug 09 '15 05:08

hfisch


People also ask

How do I scroll up page in Selenium?

We can scroll the page up or down in Selenium webdriver using Java. This is achieved with the help of the Actions class. First of all, we have to create an object of this Actions class and then apply the sendKeys method to it. Now, to scroll down a page, we have to pass the parameter Keys.

Can you scroll in Selenium?

First, we mentioned that Selenium is a tool for browser automation and it can perform many actions, including scrolling a webpage.

How do I scroll to an element in Selenium?

In Selenium we can do this with scrollIntoView(true) which can scroll automatically till the specific element is not present. You might have a requirement to scroll down the page but this requirement was different, so here I used Java Script executor, which allowed me to scroll into view.

How do you scroll down in JavaScript?

Scenario 1: To scroll down the web page by pixel. Javascript method ScrollBy() scrolls the web page to the specific number of pixels. The syntax of ScrollBy() methods is : executeScript("window. scrollBy(x-pixels,y-pixels)");


1 Answers

Assuming you got

library(RSelenium)
startServer()
remDr <- remoteDriver()
remDr$open()
remDr$setWindowSize(width = 800, height = 300)
remDr$navigate("https://www.r-project.org/about.html")

You could scroll to the buttom like this:

webElem <- remDr$findElement("css", "body")
webElem$sendKeysToElement(list(key = "end"))

And you could scroll to the top like this:

webElem$sendKeysToElement(list(key = "home"))

And in case you want to scroll down just a bit, use

webElem$sendKeysToElement(list(key = "down_arrow"))

The names of the keys are in selKeys.

like image 83
lukeA Avatar answered Sep 19 '22 10:09

lukeA