Discover the content seamlessly integrated into HTML through a Chrome extension with Selenium

I am facing an issue while using Selenium to capture text injected by a Chrome Extension. Even though the text is being injected correctly, I am struggling to make the Selenium test wait for the div to appear and then store the inner text in a variable. Can anyone help me figure out what I might be missing?

When I check the console.log, it shows "Promise { < pending> }"

Here are the snippets:

Content Script of Chrome Extension-

chrome.runtime.onMessage.addListener(
  function(request, sender, sendResponse) {

    var para = document.createElement("p");
    para.id = "selenium-container";
    var node = document.createTextNode(request.queryParameters);
    para.appendChild(node);

    window.document.body.appendChild(para);

});

Selenium Test Script -

async function Test() {
    
    let driver = builder
                    .forBrowser('chrome')
                    .withCapabilities({
                        'browserName': 'chrome',
                        'chromeOptions':
                        {
                            binary: '...',
                            args: [],
                            extensions: ['...']
                        }
                    })
                    .setChromeOptions(options)
                    .build();

    // Tests

    await driver.get('URL-HERE');

    const seleniumContainerElement = By.id("selenium-container");

    await driver.wait(until.elementLocated(seleniumContainerElement, 10000))
                .then( (seleniumContainerElement) => {
                    console.log(seleniumContainerElement.getAttribute('innerHTML'));
                });

...

Answer №1

This is the solution that worked for me:

await driver.wait(until.elementLocated(By.id('selenium-container')), 10000, 'Element not found');
await driver.findElement(By.id('selenium-container')).getText().then(function(text) {
       console.log("Content: ", text);
    });

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

What is the correct way to establish and terminate a MongoDB connection in a Node.js application?

Hey everyone, I have a piece of code at this link (https://github.com/MrRav3n/Angular-Marketplace/blob/master/server.js) and I'm curious if I am properly starting and ending my database connection. Should I connect and end the db connection in every a ...

What is the reason behind BrowserMob.GetHar() returning only one entry in C#?

My current task involves writing some straightforward C# code to automatically fetch a HAR file from the Chrome browser. I am utilizing the browser-mob-proxy tool which includes a function called GetHar() that is meant to provide various entries such as UR ...

How should one properly choose a specific <option> by its text utilizing Selenium's python driver?

I am currently engaged in web scraping using the Selenium web driver. I have successfully managed to extract the option values, but now I need to focus on extracting the option text. To achieve this, I will need to scrape the option text and pass it to you ...

What is the reason behind the appearance of 'Cannot Get/' when trying to render pug?

Attempting to configure a basic Express server with a simple pug template. Could you kindly point out what I might be doing incorrectly in this setup? 'use strict'; //Require Express var express = require('express'); var app = expres ...

Is it possible to utilize Vue's splice method within a forEach loop in order to delete multiple elements at

I am currently working on an image grid in array form. I am trying to implement a multi-deletion functionality. When a checkbox for each image in the grid is checked, I store the selected image's index in an array called selectedImages. Upon clickin ...

What is the best way to increase incrementally with Selenium POM?

Can someone help me figure out how to select two quantities of the same item in Selenium POM using a for loop? My current solution is not working, and I need to know how to increment twice in POM. Below is the file where my page objects are stored: packa ...

Error in jQuery ajax request when passing multiple variables to php script

When I use ajax to send two variables to PHP, the second variable is received correctly, but the first variable is always reported as NULL by PHP. I checked the JavaScript variable before sending it and confirmed that it contains an array of strings. I&apo ...

The scroll-to-top feature fails to function properly within the framework of Bootstrap 4

I have encountered an issue with adding a scroll to top script to my website developed using Bootstrap 4. Strangely, the script works perfectly fine on another website built with Bootstrap 3. It seems like there might be an error related to the bootstrap v ...

What are the steps to send AJAX data before closing the page?

Trying for over 7 hours to send a value to the database when the user closes the page, like online and offline. Still struggling to find a working solution. <script tysssspe="text/javascript"> //ST window.onbeforeunload = function(){ var user_st = ...

Is there a Google Maps feature that displays clusters in a dropdown

Currently, I am utilizing Google Maps to place pins all over the world and implementing markercluster.js to cluster those pins when they are nearby. One feature I am trying to incorporate is the ability to hover over a cluster of pins and have a dropdown d ...

The confusing case of jQuery's e.preventDefault: Unable to submit form despite preventing default behavior

Objective: Prevent the 'submit' button from functioning, validate fields, generate popover alerts for results, and submit form upon closing of popover. To achieve this, I have set up a hidden popover div. When the submit button is clicked, I uti ...

Unseen columns within an HTML table are also being included in the export

In my HTML table, I have included a drop-down feature for users to select the row they want to view, along with an export button that allows them to save the data in Excel format. During the exporting process, I encountered an issue where hidden rows were ...

Prevent clients from navigating the block by using AngularJS when they enter a URL in the

Is there a way to prevent navigation when the user types /pricing in the address bar, and only allow navigation when $location.path("/pricing") is triggered? when("/pricing", { templateUrl: "app/components/Pricing/pricing.html", }) I'm l ...

Troubleshooting Issue: JavaScript Confirmation Message

Presently, I have set up a popup confirm box to display as shown below: However, the issue is that I am unsure whether the user clicked 'OK' or 'Cancel'. ScriptManager.RegisterStartupScript(this, this.GetType(), "ajax", " ...

Putting Text Inside a Video Player in HTML

Is there a way to insert text, like a Logo, into my video player? https://i.sstatic.net/CZ6Rp.png I would appreciate any help on how to achieve this. Thank you. <video width="320" height="240" controls src="video/flashtrailer.mp4"> Your browser ...

What is the best way to trim a string property of an object within an array?

I am seeking a solution to access the "description" property of objects within an array and utilize a string cutting method, such as slice, in order to return an array of modified objects. I have attempted using for loops but have been unsuccessful. Here ...

Manipulator - Unveiling Discord User Profile Popup

Hey there, I'm currently working on a web project and I want to send messages in a Discord server using Puppeteer without relying on the Discord.js library. While I have successfully set up user authentication and navigated to the correct chat room, I ...

Encountering an unexpected error with the InvalidCharacterError in IE11 when using VEE Validate in conjunction with Vue.js and babel-p

Encountering an issue in IE11 where I receive an InvalidCharacterError when attempting to validate a form using vee validate in vue.js. It seems like it might be related to a polyfill error, but I'm uncertain. I have tried debugging by removing certai ...

How can express.js be properly installed using typescript?

Currently, I am in the process of setting up a new project that involves using express.js with typescript integration. Would it suffice to just install @types/express by running the following command: npm install @types/express Alternatively, do I also ...

Create a library with CSS files added, excluding any test files

As I develop a React library, I've encountered an issue where the CSS files are being ignored during the build process. In an attempt to resolve this, I included the --copy-files flag in the build script, which successful copied the CSS files but also ...