Issue with Chrome Extension in Selenium JavaScript WebDriver Test

I'm currently facing an issue with my Selenium JavaScript Webdriver test. Everything seems to be working fine, no errors are being thrown. The only problem is related to a Chrome Extension that is supposed to change the title of the page and then retrieve a cookie, but it's not functioning as expected. Interestingly, when I manually run the extension on a test page, it works perfectly. This leads me to believe that the issue lies in how I am calling the extension.

My main confusion arises from the "binary" chromeOption. After reviewing the documentation, it appears that this should point to the folder containing the extension. However, in the same docs, the "extensions" in chromeOption seem to reference a file within the same folder. Could anyone clarify what exactly should be placed under "binary"?

Here is a snippet of the code:

    const path = require('path');
    const chromePath = require('chromedriver').path;
    const webdriver = require('selenium-webdriver');
    const chrome = require('selenium-webdriver/chrome');
    const until = webdriver.until;
    var chromeOptions = webdriver.Capabilities.chrome();
    
    var service = new chrome.ServiceBuilder(chromePath).build();
    chrome.setDefaultService(service);
    
    var builder = new webdriver.Builder();
    var options = new chrome.Options();
    var preferences = new webdriver.logging.Preferences();
    var driver;
    
    preferences.setLevel(webdriver.logging.Type.BROWSER, webdriver.logging.Level.ALL);
    options.setLoggingPrefs(preferences);
    
    var extensionArray = [""];
    
    async function AppTest() {
        
        let driver = builder
                        .forBrowser('chrome')
                        .withCapabilities({
                            'browserName': 'chrome',
                            'chromeOptions':
                            {
                                binary: 
    // Folder containing a copy of the extension

'/Users/MyUserName/Desktop/Testing/chrome-extensions',
                                args: [],
    // Local copy of the extension in the same folder as the test
                                extensions: ['./chrome-extension/extension-demo.crx']
                            }
                        })
                        .setChromeOptions(options)
                        .build();
    
        // Tests
    
        await driver.get('https://testURL.com');
    
        await driver.manage().getCookie("test").then(function(cookie){
            console.log("test", cookie);
        });
    
        await driver.quit();
    }

Answer №1

I'm unfamiliar with the purpose of the "binary" key as it has not crossed my path before.

If you're interested, I detailed how to include an extension in Java on a previous post. The main takeaway is that simply adding the extension won't work; it must be converted to base-64 format first.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Steps for transforming an array of objects into an array of values based on a specific key

Is there a way to extract messages based on keywords from a JSON structure? Here is an example of the JSON structure: [{ _id: 123, message: 'hello', username: '1' }, { _id: 456, message: 'world', username: '2'}] I ...

SortTable - Refresh Dropdown Filter in Header After Adding Row to Table

My tablesorter table initially displays two entries in the "License" Filter. https://i.sstatic.net/4XODb.png If I dynamically add a row, the table now looks like this: https://i.sstatic.net/vMMYc.png I have attempted to update the table using the follow ...

Save the outcome of an ArrayBuffer variable into an array within a Javascript code

I'm in the process of developing an offline music player using the HTML5 FileReader and File API, complete with a basic playlist feature. One challenge I'm facing is how to store multiple selected files as an ArrayBuffer into a regular array for ...

Bring the element into view by scrolling horizontally

I am facing a challenge with a list of floated left divs inside another div. This inner block of divs can be hovered over to move it left and right. Each inner div, known as 'events', has class names that include a specific year. Additionally, t ...

Changing a file object into an image object in AngularJS

Can a file object be converted to an image object? I am in need of the width and height from the file (which is an image). Here is my code: view: <button id="image_file" class="md-button md-raised md-primary" type="file" ngf-select="uploadFile($file ...

Transfer a concealed input value to javascript using the href attribute

I have a question about using javascript to handle the href attribute. Here is the code snippet I am working with: <script> window.onunload = refreshParent; function refreshParent() { var SAPno = document.getElementById('Hidden ...

Tips on Including Static Header and Footer in Multiple HTML Pages

What is the best way to reuse a header and footer on multiple HTML pages without repeating code? I have 5 HTML pages that all need to include the same header and footer elements. How can I efficiently reuse these components across all pages? ...

Selenium webdriver encounters an issue when used within a Docker container

I've been facing this issue for a while now. I am attempting to create a Docker container that utilizes selenium Webdriver to scrape data, but I encountered an error stating that the driver is not callable. The error message is as follows: > [stag ...

Error in Mongodb: Unable to convert value into ObjectId

Currently, I am attempting to retrieve only the posts belonging to users using the following code snippet: router.get("/:username", async (req, res) => { try { const user = await User.findOne({ username: req.params.username }); const ...

What strategies can be used to efficiently perform Asynchronous Operations on a high volume of rows in a particular database table?

I am looking to perform Asynchronous Operations on every row of a specific database table, which could potentially contain 500,000, 600,000, or even more rows. My initial approach was: router.get('/users', async (req, res) => { const users = ...

Curious about examining an AJAX/HTTP request using Protractor/Webdriver? Want to see the data returned by $HttpBackend?

Can Protractor/Webdriver be used to monitor $http/AJAX requests made by the browser? Is there a method for retrieving the request sent to $http-backend? ...

Here's a guide on how to display texts underneath icons in Buttons using Material UI

Currently, this is the Button I have displayed https://i.sstatic.net/YkHp0.png I am trying to figure out how to position the Dummy Button text beneath the icon. Can someone assist me with this? Below is my code snippet: <Button className={classes.d ...

The error message from the mongoose plugin is indicating a problem: it seems that the Schema for the model "Appointment" has not been properly registered

I need help troubleshooting a mongoose error that is being thrown. throw new mongoose.Error.MissingSchemaError(name); ^ MissingSchemaError: Schema hasn't been registered for model "Appointment". Use mongoose.model(name, schema) I have double-c ...

When calling an API endpoint, nodeJS is unable to access the local path

I've encountered a strange issue with my code. When I run it as a standalone file, everything works perfectly fine. However, when I try to utilize it in my API endpoint and make a request using Postman, it doesn't seem to function properly. What ...

Steps to verify the current time and execute a task if it matches the designated time

After successfully implementing a time function which changes the value of an input text based on a specific time, I encountered an issue. Although the time function is designed to change the input text value to 1 when the time reaches 2:30:35 PM... if(b ...

Tips for preventing the use of nested functions while working with AJAX?

Consecutively making asynchronous calls can be messy. Is there a cleaner alternative? The issue with the current approach is its lack of clarity: ajaxOne(function() { // do something ajaxTwo(function() { // do something ajaxThree() }); }); ...

Ways to extract viewership data from YouTube websites

Most of my code is running smoothly Right now, I'm able to fetch all the titles from a youtube page and scroll through them. But how can I retrieve the number of views? Would CSS or xPath be suitable for this task? import time from selenium import ...

Tips on adjusting a JavaScript animation function

I'm currently working on adjusting the animation function within the "popup" class that controls the gallery section of a website. When the page loads, an image and background start expanding from zero scale in the center to 100 VIEWPORT HEIGHT (VH) a ...

"Is there a way to retrieve the CSS of all elements on a webpage by providing a URL using

Currently, I am in the process of creating a script that can crawl through all links provided with a site's URL and verify if the font used on each page is helvetica. Below is the code snippet I have put together (partially obtained online). var requ ...

Insert information into a nested array using Mongoose

I'm encountering an issue with my code, even though I know it may be a duplicate. Here is the snippet causing me trouble: exports.addTechnologyPost = function(req, res){ console.log(req.params.name); var query = { name: 'test ...