{playwrightr} provides access the python library playwright
Playwright emulates web browsers and enables reliable end-to-end testing for modern web apps.
- Install playwright (in this example, we install playwright in a new conda environment)
conda create -n pw python=3.7
conda activate pw
conda config --add channels conda-forge
conda config --add channels microsoft
conda install playwright
playwright install
- Install playwrightr from GitHub
# install.packages("devtools")
devtools::install_github("benjaminguinaudeau/playwrightr")
This is a basic example which shows you how to solve a common problem:
reticulate::use_python("/home/ben/anac/bin/python", required = TRUE)
options(python_init = TRUE)
library(reticulate)
library(playwrightr)
library(dplyr)
pw_init(use_xvfb = F)
# Launch the browser
browser_df <- browser_launch(browser = "firefox", user_data_dir = tempdir(), headless = T)
# Create a new page
page_df <- new_page(browser_df)
page_df %>%
goto("https://google.com")
page_df %>%
get_by_selector("input") %>%
split(1:nrow(.)) %>%
purrr::map_dfr(~{
attrs <- get_all_attributes(.x)
attrs
}) %>%
glimpse
chrome <- new_browser("chrome", headless = F)
page <- chrome$pages[[1]]
page$goto("https://google.com")