Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

402
Views
Scrolling element into view using javascrpit in RSelenium

I have following page

https://en.wikipedia.org/wiki/R_(programming_language)

I want to scroll until Milestones heading so that it is visible in browser,

My code,

library(RSelenium)
driver = rsDriver(browser = c("firefox"))

remDr <- driver[["client"]]

url = 'https://en.wikipedia.org/wiki/R_(programming_language)'
remDr$navigate(url)

I know that,

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

and

remDr$executeScript("window.scrollTo(0,document.body.scrollHeight);")

gets me to the end of page.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

We can scroll using java script to get the element (Milestone) into view by,

#navigate to webpage
url = 'https://en.wikipedia.org/wiki/R_(programming_language)'
remDr$navigate(url)

Identify the element,

ele = remDr$findElement(using = "xpath",'//*[@id="Milestones"]')
#scroll into view
remDr$executeScript("arguments[0].scrollIntoView(true);", list(ele))

enter image description here

Additional info,

To scroll to the middle of the page we can use,

remDr$executeScript("window.scrollTo(0,document.body.scrollHeight/2);")
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!