skip to Main Content

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.

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    This is the solution I found.

    1. 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.

    2. 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")
      

  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search