Selinput is a wrapper for the python API pyautogui, which allows to simulate input from a real mouse and keyboard in a Docker container.
devtools::install_github("benjaminguinaudeau/selinput")
library(selinput)
Get a few more libraries
#devtools::install_github("benjaminguinaudeau/tidyweb")
pacman::p_load(tidyverse, selinput, dockeR, tidyselenium)
Start a container and a browser
# First Container
chrome_container <- docker$new(
image_src = "selenium/standalone-chrome-debug", #Image to be used (model for the container)
container_name = "chrome",
other_arguments = "-p 4446:4444 -p 4447:5900"
# Name you want to use
)
chrome <- tidyselenium::get_driver(4446)
chrome$open()
If you don’t have pyautoguy
installed yet, run the following:
selinput::doc_init_pyautogui(chrome)
This should return TRUE
selinput::is_pyautogui_installed(chrome)
Get a screenshot (currently broken?)
chrome %>%
go("https://news.google.com/") %>%
selinput::doc_screenshot(file = "screenie.png")
List of hotkeys that can be pressed:
hot_keys %>% sample(10) %>% glimpse
## press tab
chrome %>%
selinput::doc_hot_keys(key = hot_keys$tab)
## press enter
chrome %>%
selinput::doc_hot_keys(key = hot_keys$enter)
Type on keyboard:
## Type on Keyboard
chrome %>%
selinput::doc_type(key = "Hello! My name is Fitzgerald.")
A huge thank you to Favstats for designing each of the hex-stickers.