selenium-r

Low-Level Browser Automation Interface

https://github.com/ashbythorpe/selenium-r

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (16.6%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Low-Level Browser Automation Interface

Basic Info
Statistics
  • Stars: 20
  • Watchers: 2
  • Forks: 2
  • Open Issues: 0
  • Releases: 3
Created over 2 years ago · Last pushed 12 months ago
Metadata Files
Readme Changelog License Codemeta

README.Rmd

---
output: github_document
---



```{r, include = FALSE}
available <- selenium::selenium_server_available()
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%",
  eval = available
)
```

```{r eval = !available, echo = FALSE, comment = NA}
if (!available) {
  message("Selenium server is not available.")
}
```

# selenium


[![R-CMD-check](https://github.com/ashbythorpe/selenium-r/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ashbythorpe/selenium-r/actions/workflows/R-CMD-check.yaml)
[![CRAN status](https://www.r-pkg.org/badges/version/selenium)](https://CRAN.R-project.org/package=selenium)


selenium is a tool for the automation of web browsers. It is a low-level interface 
to the [WebDriver](https://w3c.github.io/webdriver/) specification, and an up-to-date
alternative to [RSelenium](https://github.com/ropensci/RSelenium).

## Installation

``` {r eval = FALSE}
# Install selenider from CRAN
install.packages("selenium")

# Or the development version from Github
# install.packages("pak")
pak::pak("ashbythorpe/selenium-r")
```

However, you must also have a selenium server installed and running (see below).

## Starting the server
A selenium instance consists of two parts: the client and the server.
The selenium package *only provides the client*. This means that you
have to start the server yourself. 

To do this you must:

* Install a browser that you want to automate (e.g. Chrome, Firefox, Edge).
* Download [Java](https://www.oracle.com/java/technologies/downloads/) (you need Java 11 or higher).

There are many different ways to download and start the server, one of which
is provided by selenium:

```{r setup}
library(selenium)
```

```{r eval = FALSE}
server <- selenium_server()
```

This will download the latest version of the server and start it.

By default, the server file will be stored in a temporary directory, meaning it
will be deleted when the session is closed. If you want the server to persist,
meaning that you don't have to re-download the server each time, you can use
the `temp` argument:

``` {r eval = FALSE}
server <- selenium_server(temp = FALSE)
```

You can also do this manually if you want:

1. Download the latest `.jar` file for Selenium Server. Do this by navigating to
   the latest GitHub release page (),
   scrolling down to the **Assets** section, and downloading the file named 
   `selenium-server-standalone-.jar` (with `` being the latest release version).
2. Make sure you are in the same directory as the file you downloaded.
3. In the terminal, run `java -jar selenium-server-standalone-.jar standalone --selenium-manager true`,
   replacing `` with the version number that you downloaded. This will download
   any drivers you need to communicate with the server and the browser, and start the server.

There are a few other ways of starting Selenium Server:

* Using docker to start the server. See .
  This is recommended in a non-interactive context (e.g. GitHub Actions).
* Using the `wdman` package to start the server from R, using `wdman::selenium()`. Note
  that at the time of writing, this package does not work with the latest version of
  Chrome.

## Waiting for the server to be online

The Selenium server won't be ready to be used immediately. If you used
`selenium_server()` to create your server, you can pass it into
`wait_for_server()`:

``` {r eval = FALSE}
wait_for_server(server)
```

You can also use `server$read_output()` and `server$read_error()`

If you used a different method to create your server, use
`wait_for_selenium_available()` instead.

``` {r eval = FALSE}
wait_for_selenium_available()
```

If any point in this process produces an error or doesn't work, please see the
[Debugging Selenium](https://ashbythorpe.github.io/selenium-r/articles/debugging.html)
article for more information.

## Starting the client

Client sessions can be started using `SeleniumSession$new()`
``` {r eval = FALSE}
session <- SeleniumSession$new()
```

By default, this will connect to Firefox, but you can use the `browser` argument to specify
a different browser if you like.

```{r session}
session <- SeleniumSession$new(browser = "chrome")
```

## Usage

Once the session has been successfully started, you can use the session
object to control the browser. Here, we dynamically navigate through
the R project homepage. Remember to close the session and the server process
when you are done.

```{r example}
session$navigate("https://www.r-project.org/")
session$
  find_element(using = "css selector", value = ".row")$
  find_element(using = "css selector", value = "ul")$
  find_element(using = "css selector", value = "a")$
  click()

session$
  find_element(using = "css selector", value = ".row")$
  find_elements(using = "css selector", value = "div")[[2]]$
  find_element(using = "css selector", value = "p")$
  get_text()

session$close()
```
``` {r eval = FALSE}
server$kill()
```

For a more detailed introduction to using selenium, see the
[Getting Started](https://ashbythorpe.github.io/selenium-r/articles/selenium.html)
article.

Note that selenium is low-level and mainly aimed towards developers. If you are
wanting to use browser automation for web scraping or testing, you may want to
take a look at [selenider](https://github.com/ashbythorpe/selenider) instead.

Owner

  • Name: Ashby Thorpe
  • Login: ashbythorpe
  • Kind: user

R enthusiast

CodeMeta (codemeta.json)

{
  "@context": "https://doi.org/10.5063/schema/codemeta-2.0",
  "@type": "SoftwareSourceCode",
  "identifier": "selenium",
  "description": "An implementation of 'W3C WebDriver 2.0' (<https://w3c.github.io/webdriver/>), allowing interaction with a 'Selenium Server' (<https://www.selenium.dev/documentation/grid/>) instance from 'R'. Allows a web browser to be automated from 'R'.",
  "name": "selenium: Low-Level Browser Automation Interface",
  "relatedLink": [
    "https://ashbythorpe.github.io/selenium-r/",
    "https://CRAN.R-project.org/package=selenium"
  ],
  "codeRepository": "https://github.com/ashbythorpe/selenium-r",
  "issueTracker": "https://github.com/ashbythorpe/selenium-r/issues",
  "license": "https://spdx.org/licenses/MIT",
  "version": "0.2.0",
  "programmingLanguage": {
    "@type": "ComputerLanguage",
    "name": "R",
    "url": "https://r-project.org"
  },
  "runtimePlatform": "R version 4.5.0 (2025-04-11)",
  "provider": {
    "@id": "https://cran.r-project.org",
    "@type": "Organization",
    "name": "Comprehensive R Archive Network (CRAN)",
    "url": "https://cran.r-project.org"
  },
  "author": [
    {
      "@type": "Person",
      "givenName": "Ashby",
      "familyName": "Thorpe",
      "email": "ashbythorpe@gmail.com",
      "@id": "https://orcid.org/0000-0003-3106-099X"
    }
  ],
  "copyrightHolder": [
    {
      "@type": "Person",
      "givenName": "Ashby",
      "familyName": "Thorpe",
      "email": "ashbythorpe@gmail.com",
      "@id": "https://orcid.org/0000-0003-3106-099X"
    }
  ],
  "maintainer": [
    {
      "@type": "Person",
      "givenName": "Ashby",
      "familyName": "Thorpe",
      "email": "ashbythorpe@gmail.com",
      "@id": "https://orcid.org/0000-0003-3106-099X"
    }
  ],
  "softwareSuggestions": [
    {
      "@type": "SoftwareApplication",
      "identifier": "gitcreds",
      "name": "gitcreds",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=gitcreds"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "testthat",
      "name": "testthat",
      "version": ">= 3.0.0",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=testthat"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "withr",
      "name": "withr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=withr"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "xml2",
      "name": "xml2",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=xml2"
    }
  ],
  "softwareRequirements": {
    "1": {
      "@type": "SoftwareApplication",
      "identifier": "R",
      "name": "R",
      "version": ">= 2.10"
    },
    "2": {
      "@type": "SoftwareApplication",
      "identifier": "base64enc",
      "name": "base64enc",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=base64enc"
    },
    "3": {
      "@type": "SoftwareApplication",
      "identifier": "httr2",
      "name": "httr2",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=httr2"
    },
    "4": {
      "@type": "SoftwareApplication",
      "identifier": "jsonlite",
      "name": "jsonlite",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=jsonlite"
    },
    "5": {
      "@type": "SoftwareApplication",
      "identifier": "lifecycle",
      "name": "lifecycle",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=lifecycle"
    },
    "6": {
      "@type": "SoftwareApplication",
      "identifier": "processx",
      "name": "processx",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=processx"
    },
    "7": {
      "@type": "SoftwareApplication",
      "identifier": "R6",
      "name": "R6",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=R6"
    },
    "8": {
      "@type": "SoftwareApplication",
      "identifier": "rappdirs",
      "name": "rappdirs",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=rappdirs"
    },
    "9": {
      "@type": "SoftwareApplication",
      "identifier": "rlang",
      "name": "rlang",
      "version": ">= 1.1.0",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=rlang"
    },
    "SystemRequirements": null
  },
  "fileSize": "325.855KB",
  "releaseNotes": "https://github.com/ashbythorpe/selenium-r/blob/master/NEWS.md",
  "readme": "https://github.com/ashbythorpe/selenium-r/blob/main/README.md",
  "contIntegration": "https://github.com/ashbythorpe/selenium-r/actions/workflows/R-CMD-check.yaml"
}

GitHub Events

Total
  • Create event: 4
  • Release event: 1
  • Issues event: 5
  • Watch event: 4
  • Delete event: 2
  • Issue comment event: 7
  • Push event: 13
  • Pull request event: 5
Last Year
  • Create event: 4
  • Release event: 1
  • Issues event: 5
  • Watch event: 4
  • Delete event: 2
  • Issue comment event: 7
  • Push event: 13
  • Pull request event: 5

Issues and Pull Requests

Last synced: 10 months ago

Packages

  • Total packages: 1
  • Total downloads:
    • cran 351 last-month
  • Total dependent packages: 1
  • Total dependent repositories: 0
  • Total versions: 4
  • Total maintainers: 1
cran.r-project.org: selenium

Low-Level Browser Automation Interface

  • Versions: 4
  • Dependent Packages: 1
  • Dependent Repositories: 0
  • Downloads: 351 Last month
Rankings
Forks count: 28.0%
Dependent packages count: 29.0%
Stargazers count: 34.7%
Dependent repos count: 37.0%
Average: 43.1%
Downloads: 86.8%
Maintainers (1)
Last synced: 10 months ago