Can anyone give me a hand to figure out how to activate a chrome extension with RSelenium?
Extensions are located in the tab of the browsers, but are not preloaded when using RSelenium.
The remDr variable you create is a "remote driver", an object that handles communication with the browser that's running in the background. You don't want to send keys there, you want to send them to some object in the web page that is being displayed.
Depending on the web page, that might be a specific field (e.g. the user name field in a login page), or something bigger. Usually you would use elem <- remDr$findElement(...) to find the element of the web page, then elem$sendKeysToElement(...) to send them.
I'm not sure which element on your web page will handle the keys. I'd guess something like this will work:
elem <- remDr$findElement("xpath", "//body")
elem$sendKeysToElement(list(key = 'control', key = 'shift', 's'))
but you may need to experiment with the first liine.
list(key = 'control', key = 'shift', 's') should simulate a Ctrl-Shift-s. I'd guess the most likely problem is that "//body" is the wrong element to receive the key, but maybe you need different modifiers: on my Mac on that page Ctrl-Shift-s does nothing, but Command-Shift-s starts up some kind of region selection. I don't know how to determine which element is listening for keys.This is the solution I found.
Convert the extension to a .crx file.
step a. navigate to chrome://extensions/
step b. click on "developer mode"
step c. click on pack extension. Here I assume you already have the extension up and working.
step d. browse to the folder where the extension was saved. Commonly around this place:
C:/Users/YOURUSERNAME/AppData/Local/Google/Chrome/User Data/Default/Extensions/ekhagklcjbdpajgpjgmbionohlpdbjgc/5.0.114_0
step e. click "Pack extension" this will create a .crx file of your extension, which will be placed in the same path as above.
Load the .crx file as part of the preferences for chrome
#Adjust path accordingly. You can rename the file if you like
PathToCRX="C:/Users/MyExtension.crx" #
cprof <- list(chromeOptions =
list(extensions =
list(base64enc::base64encode(PathToCRX))
))
rD <- rsDriver(port = 4444L,extraCapabilities=cprof, browser ="chrome",chromever = "latest")