Site icon R-bloggers

Step-by-Step Guide to Use RSelenium with Firefox (Linux and Windows)

[This article was first published on https://pacha.dev/blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
< !DOCTYPE html> < charset="utf-8"> < http-equiv="X-UA-Compatible" content="IE=edge"> < name="viewport" content="width=device-width, initial-scale=1.0"> pacha.dev/blog < !-- MathJax Configuration --> < !-- Smart header: libraries detected based on content --> < !-- File: /tmp/tmp.Syyv32j1AB/index.html -->
  • < !-- DEBUG: Found sourceCode --> < !-- Load custom CSS after any library CSS to ensure proper precedence -->
  • < header class="site-top">

    Mauricio “Pachá” Vargas Sepúlveda

    Blog with notes about R, Shiny, SQL, Python, Linux and C++. This blog is listed on R-Bloggers.

    HOME 🏠
    < !-- categories are printed below this--> < nav class="sidebar-nav">

    Categories

    < header id="title-block-header" class="quarto-title-block default">

    Step-by-Step Guide to Use RSelenium with Firefox (Linux and Windows)

    Using RSelenium and Firefox to organize hundreds of HTML sections into one table.
    Author

    Mauricio “Pachá” Vargas S.

    Published

    September 5, 2025

    Because of delays with my scholarship payment, if this post is useful to you I kindly ask a minimal donation on Buy Me a Coffee. It shall be used to continue my Open Source efforts. The full explanation is here: A Personal Message from an Open Source Contributor.

    You can send me questions for the blog using this form and subscribe to receive an email when there is a new post.

    < section id="motivation" class="level2">

    Motivation

    Continuing with the previous post, here I expand the instructions for Windows and Linux (I do not have a Mac laptop to test on OS X).

    < section id="required-software" class="level2">

    Required software

    • Mozilla Firefox and GeckoDriver: web browser and remote control program
    • RSelenium: R-Selenium integration
    • rvest: HTML processing
    • dplyr: to load the pipe operator (can be used later for data cleaning)
    • purrr: iteration (i.e., repeated operations)
    < section id="mozilla-firefox-and-geckodriver" class="level3">

    Mozilla Firefox and GeckoDriver

    < section id="windows" class="level4">

    Windows

    I installed Mozilla Firefox from the official website and followed the installer.

    For GeckoDriver, I downloaded it from here for Windows 64-bit and saved “geckodriver.exe” to a new folder “C:”. Then, I had to add the folder to the PATH like this:

    1. Press Win + S
    2. Type “Environment variables”
    3. Open “Edit the system environment variables”.
    4. Click “Environment variables”.
    5. In “System variables”, find and select “Path”, then click “Edit”.
    6. Click “New” and add “C:” without quotes
    7. Click OK to save.

    Then restart RStudio and close PowerShell if it is open. Not installing GeckoDrive would only result in this error message in R: “Unable to create new service geckodriverservice.”

    < section id="linux" class="level4">

    Linux

    I use Manjaro, so Firefox is the default browser.

    To install GeckoDriver I used these commands:

    wget https://github.com/mozilla/geckodriver/releases/download/v0.36.0/geckodriver-v0.36.0-linux64.tar.gz -O ~/Downloads/geckodriver.tar.gz
    tar -xzf ~/Downloads/geckodriver.tar.gz -C ~/Downloads
    rm ~/Downloads/geckodriver.tar.gz
    sudo mv ~/Downloads/geckodriver /usr/local/bin/
    geckodriver --version

    the output should show “geckodriver 0.36.0”.

    < section id="rselenium-and-selenium-server" class="level4">

    RSelenium and Selenium Server

    I installed RSelenium from the R console:

    if (!require(RSelenium)) install.packages("RSelenium")
    
    # or
    
    remotes::install_github("ropensci/RSelenium")

    I tried to start Selenium as it is mentioned in the official guide and it did not work.

    I downloaded Selenium Server from this link.

    For the rest of the packages:

    if (!require(rvest)) install.packages("rvest")
    if (!require(dplyr)) install.packages("dplyr")
    if (!require(purrr)) install.packages("purrr")
    < section id="running-selenium-server" class="level2">

    Running Selenium Server

    These commands work on PowerShell (Windows) and sh/bash/zsh (Linux):

    cd Downloads
    java -jar selenium-server-standalone-3.9.1.jar

    The Selenium Server instance has to be run every time before running the R code unless the terminal remains open.

    < section id="controlling-the-browser" class="level2">

    Controlling the Browser

    From RStudio (same for an R terminal), I could control the browser from R:

    library(RSelenium)
    library(rvest)
    library(dplyr)
    library(purrr)
    
    rmDr <- remoteDriver(port = 4444L, browserName = "firefox")
    
    rmDr$open(silent = TRUE)
    
    url <- "https://pacha.dev/blog"
    
    rmDr$navigate(url)

    This should display a new Firefox window and show my blog. The rest of the steps are the same as in the original post where I show practical examples.

    I hope this is useful 🙂

    < footer>

    Loading…

  • < !-- Load shared sidebar -->
    To leave a comment for the author, please follow the link and comment on their blog: https://pacha.dev/blog.

    R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
    Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
    Exit mobile version