Developing a new webpage component in Selenium using C# and retrieving the corresponding feedback

I am currently working on adding a new element and I need to retrieve a URL as the response. However, I am unsure of how to capture the response from this new element. Any advice or suggestions would be highly appreciated.

public void Initialize()
    {
        IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
        driver = new ChromeDriver("C:\\SeleniumDrivers\\");
        driver.Navigate().GoToUrl("https://www.target.com");
        driver.Manage().Window.Maximize();
        Thread.Sleep(3000);
        string scriptExecution = "var document = window.document;"+
        "var head = window.getElementByTagName(\"head\");"+
        "var script = window.createElement(\"script\");" +
        "script.setAttribute(\"type\", \"text/javascript\");" +
        "script.setAttribute(\"src\", \"https://go.playerzero.ai/record/6274691b00fbad01561df689\");"+
        "head.appendChild(script);";
        try
        {
            js.ExecuteScript(scriptExecution);

        }
        catch (Exception error)
        {
            System.Diagnostics.Debug.WriteLine(error);
        }
    }

Answer №1

Update your code to retrieve the src:

Check out this functional example utilizing .NET6, Selenium.WebDriver 4.3.0, and

Selenium.WebDriver.ChromeDriver 103.0.5060.5300

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

const string Url = @"https://www.target.com";

using var driver = new ChromeDriver();
driver.Navigate().GoToUrl(Url);

var script = @"let script = document.createElement('script');
              script.type = 'text/javascript';
              script.src = 'https://go.playerzero.ai/record/6274691b00fbad01561df689';
              document.head.appendChild(script);
              return script.src;";

var js = (IJavaScriptExecutor)driver; 
var src = js.ExecuteScript(script).ToString();

Console.WriteLine(src);

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

Tips for designing table rows with varying column lengths using CSS and JavaScript

I am facing an issue while populating my table with data from a list. Currently, the table cells are being filled from left to right, but I want them to be populated from top to bottom. Unfortunately, I am unsure how to achieve this using a list method. ...

In Javascript, comparing a regular array value with an array value created by the match function

I'm experiencing a problem with comparing values in two different arrays. Here is the code snippet: tagNames = []; tagNames.push('61'); cmt_wrds = '‏‏61'.replace(/[`~!@#$%^&*()_|+\-=?;:&apos ...

Why is the Slick Slider displaying previous and next buttons instead of icons?

I'm currently working on creating a slider using the slick slider. Everything seems to be functioning properly, but instead of displaying arrows on the sides, it's showing Previous and Next buttons stacked vertically on the left side. It appears ...

Having a hiccup in my code. The webpage is opening fine, but I'm encountering an error when trying to input text into the search box. I'm still a beginner in Python,

from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Chrome("C:\\Users\\rahuls1\\chromedriver.exe") driver.get('https://www.pastemagazine.com/') elem = driver.find_eleme ...

Select Data from SQL Query and Display in Dropdown Menu

Is there a way to access the 2nd value returned from an SQL Query without making another call to the server? I know how to assign the 1st value to my drop down list, but I'm unsure of how to retrieve the employeeid value later in my runaquery method. ...

"Utilizing ASP button with client-side history back function on OnClientClick

Hey there, I am having an issue with my asp button that I created using the code below: <asp:Button ID="btnBack" OnClientClick='javascript:history.back()' runat="server" Text="back"> </asp:Button> Strangely, the javascript function ...

Looking for a website to conduct load testing? You'll need to log in first in order to access

I am in the process of developing an Automated Testing Python Project to conduct comprehensive testing on a website. This project involves executing Functionality, Accessibility, and Load Testing on the website, with detailed reporting of the outcomes. The ...

Traversing a hierarchical JSON structure reminiscent of a tree object

I am working with a complex object structure, var cObj = { name: 'Object1', oNumbers: 3, leaf: [ { name: 'Inner Object 1', oNumbers: 4, leaf: [] }, { name: 'Inner Object 2', oN ...

Utilize the results of the "event's" output as a variable

Struggling with manipulating checkbox values? The `change` event on checkboxes might return an object like this: {"val1":"member","val2":"book","val3":"journal","val4":"new_member","val5":"cds"} To transform the above object into a format that can be co ...

Conceal the second click action within the anchor tag

Is there a way to hide the second click event on all anchor tags except those that trigger popupfun? I have a sample page set up. [Check out the JS Fiddle here][1] http://jsfiddle.net/ananth3087/LgLnpvf4/15/ Link Anchor Tags: The page includes two ...

Retrieve the width of an element once the browser has finalized its dimensions

I am facing an issue with centering a pop-up box perfectly within the window using CSS properties. The code for the pop-up box styling is as follows: #pop_up { position: fixed; display: inline-block; border: 2px solid green; box-shadow: 0p ...

Increment field(s) conditionally while also performing an upsert operation in MongoDB

I need to perform an insert/update operation (upsert) on a document. In the snippet below, there is a syntactical error, but this is what I am attempting to achieve: $inc: { {type=="profileCompletion"?"profileCompletion":"matchNotification"}: 1}, If the ...

Locating and Exiting a Popup Box in Firefox with Selenium and C#

Problem: I am encountering issues with my Selenium script where it is unable to recognize and close a dialog box that appears when redirecting to a URL containing a file download. The dialogue box in question can be seen in the attached image. Despite ded ...

Tips for updating a cell's value in a DataGridview when another cell's value changes

Let's say I want to modify the MRP column. The task involves multiplying that specific value by another column value named No_of_Units, with the outcome then being placed in a column labeled Total. I appreciate your help on this matter. ...

Python WebDriver in Selenium: Using Conditional Statements for Element Selection

In my current situation, I am dealing with a modal that may or may not have a Facebook login button directly available. Sometimes I need to click on 'More Options' to access the Facebook button. The challenge here is that the xpath for the more_o ...

Exploring the setTimeout function in JavaScript

As I understand it, the setTimeout function creates a new thread that waits for x milliseconds before executing the JavaScript function. setTimeout(functionName, timeInms); My question is: Is there a way to instruct it to run after all other JS on the pa ...

When one div is hidden, the width of another div will automatically adjust to 100%

Is there a way to make #leftdiv expand to 100% when #rightdiv is hidden, and have both <div>s positioned next to each other when a button is clicked? I have successfully aligned both <div>s next to each other upon button click, but I would lik ...

Hold on for the useState object to contain a value

Created a custom hook that fetches the user's location and determines the nearest marker on a map based on that information. Initially, it returns the default value of useState. The response looks like this: { coordinates: { lat: '', lng: ...

Guidelines on integrating Admob into Ionic framework

I tried following the steps outlined in this post: AdMob not loading ads in ionic/angular app After running the app using "ionic build ios && ionic emulate ios," I still see no ads, no black bar, nothing at all. Can someone help me figure out wha ...

Verifying Role Permissions for Method Accessibility through Unit Testing

How can I test whether an authorize attribute on a method or controller in a WebApi/MVC project has specific role(s)? For example, is it possible to test a method like the one below? [Test] [TestCase("Put", new []{"Admin","TeamMember"})] [Tes ...