0

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 2

0

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.

Sign up to request clarification or add additional context in comments.

4 Comments

This makes sense. I tested it but nothing happens... I think one needs the command for pushdown key.... would you know which one is it? control+shift+s, is not the same as control (keydown) + shift(keydown) + s.... thank you...
According to the docs, the modifier keys should be "sticky", so 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.
got it. I am testing different element with no success... if I were to simply move the cursor to the page and push control+shift+s the pop-up window for the zotero extension pups-up right away. I also know the keys are being sent... so the only two options are that the control shift s are not all pressed at the time, which you said they should. and the other option is then over which element to send those keys... i have tried over every element I can see with no luck yet.
Are there any other keystrokes that cause actions on that website? Maybe try them and see if the double modifier is the problem.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.