Discover the method of connecting to a unique JavaScript trigger while utilizing IJavaScriptExecutor

In our web application, we have an event called timelineEventClicked that is created by a custom trigger.

canvas.addEventListener('click', function (evt) {
                    evt.stopImmediatePropagation();
                    var mousePos = getMousePos(canvas, evt);

                        ...//some manipulation here

                        $.event.trigger({
                            type: "timelineEventClicked",
                            sender: _timelineObject,
                            events: settings.events,
                            eventData: eventData
                        });
                    });

I am looking to connect to the timelineEventClicked event and retrieve the eventData using selenium or protractor through injection.

IJavaScriptExecutor executor = (IJavaScriptExecutor)driver;
 executor.ExecuteScript(@"(function() {                       
                    document.addEventListener('timelineEventClicked', function(e) {
                        //Not sure what to do here to get back eventData
                })();"
                );

The issue I am facing is that the event timelineEventClicked seems to be unrecognized, and I am unsure why this is happening.

Answer №1

In order to retrieve the event, it is important to save it in the global scope along with the listener. Afterward, the event can be triggered by clicking on the canvas and the variable can be returned:

Utilize the IJavaScriptExecutor interface to access the driver object:

IJavaScriptExecutor executor = (IJavaScriptExecutor)driver;

// Set up the listener
executor.ExecuteScript(
  "$(document).on('timelineEventClicked', function(e){ window._evt=e; });");

// Click on the canvas to trigger the event
driver.FindElement(...).Click();

// Retrieve the event data
var data = executor.ExecuteScript(@"return window._evt;");

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

Summon the keyboard to appear

How do I make the keyboard appear on my website? I have a javascript function that recognizes keyboard input, but I am struggling to display the keyboard on my mobile device. Is there a way to simulate traditional input and generate key events? I should ...

How can we stop self shadowed faces from being illuminated?

Currently, I am working on creating a city scene in Three.js and experimenting with lighting and shadows. Specifically, I am focusing on a single building that was modeled in 3DS Max, then exported to OBJ format, and converted using a Python converter thro ...

Configuring Appium for executing automated scripts in Java for iOS applications using .ipa files on a Mac machine

I'm wondering if it's possible to test an iOS app on a Mac using Appium with just the .ipa file, without having to build the app in Xcode. Building the app can be time-consuming, so I'm hoping there's a way to avoid that step. If anyone ...

Retrieving the Minimum and Maximum Dates from a Table Column in ASP

I am attempting to retrieve the minDate from columnOne and maxDate from columnTwo using a C# Class Library for SharePoint. Below is my code: SPListItemCollection itemsTable = list.GetItems(queryForTable); List<DateTime> minDateList = new List< ...

Combine multiple key values from an array of objects into a single array

I have a set of key and value pairs that I need to filter based on whether the values are in an array or not, and then combine them into a single array. const holiday_expenses = { food: [{name: "abc", place: "xyz"}], travel: [{name: ...

Working with Linq in JSON Serialization

Below is a json string that I have: { 'Sheet1': [{ 'EmployeeNo': '123456', 'EmployeeName': 'Midhun Mathew' }, { 'EmployeeNo': '123457& ...

Guide to retrieving a string value rather than Json output with a mongodb aggregate function

I have a function that retrieves the value of the 'minHospitalization' field from the database. The response from this function is '[{"minHospitalization":1}]' Instead of returning the value in JSON format, I want to return just ' ...

JQuery class for swapping elements upon scrolling

I am currently working on a navigation bar that changes classes to create a fading effect for the background. The approach I have taken involves targeting the window itself and monitoring the scroll position of the user. If the user scrolls down more than ...

Having trouble with sending an AJAX request to a different domain?

I've been attempting to utilize the following API: However, upon making an AJAX call, I encounter this specific error: XMLHttpRequest cannot load /radius.json/30341/10/mile. No 'Access-Control-Allow-Origin' header is present on ...

Is it possible for me to convert a .map array into a comma-separated array enclosed in double quotation marks?

I am attempting to extract data from a group of twig variables and convert them into a javascript plugin. The data consists of dates listed in an array format. Initially, they are displayed on the template as a string like this: {"date":"2018-08-30, 2018- ...

What is the functionality of Vue plugins in Vite MPAs?

I have developed a Vite application and I am trying to implement multiple pages. I followed the documentation on how to achieve this (link here), but when I start the server, all I see is a blank page. This is what my vite.config.js file looks like: impor ...

Is it possible for a JavaScript .execute function to be executed synchronously, or can it be transformed into an Ajax

Currently, I am utilizing the ArcGIS API for Javascript which can be found at this URL: The JavaScript code snippet I'm working with appears to be running asynchronously. Is there a way to convert it to run synchronously or potentially transform it i ...

What is the best way to save a token value to a JavaScript file on my local storage

Hello, I am new to Nodejs and have implemented passportjs token-based authentication. When a user logs in, a token is provided for each user. Now, I want to perform certain operations based on the users who have token values. For example, if a user wants t ...

Encountering the 404 Page Not Found error upon refreshing the page while utilizing parallel routes

I'm currently developing a webapp dashboard using the latest version of Next.js 13 with app router. It features a dashboard and search bar at the top. I attempted to implement parallel routes. The @search folder contains the search bar and page.jsx wh ...

What is the functionality of the keydown event?

Whenever the input text value is not empty, I want my .removetext div to be displayed, but it's not working correctly. When I type something after the second character, my .removetext gets hidden, but it shouldn't be hidden when the input is not ...

Passing the title of a page as data to a component in Next.js

I am currently working on setting a custom title for each page within my next.js project. Here is an example of a simple Layout: const MainLayout = props => { return ( <Layout style={{ minHeight: "100vh" }}> <Head> < ...

Tips for managing multiple popups simultaneously

I recently received a question about handling multiple popups in Selenium WebDriver, but I must admit that I am not entirely sure. However, let's assume we are attempting to handle 3 popups on our screen. Here is one possible approach: 1. Get the w ...

What is the best way to incorporate a search feature within Bootstrap cards?

I've been struggling to incorporate a search feature within my bootstrap cards. Despite trying various online methods, none have proven successful for me so far. Below is my HTML code - any assistance in implementing a search filter into my app would ...

JQuery grid pagination bar mysteriously missing

I'm having an issue with a Jquery grid that is built on an HTML table. I've properly configured the grid properties, including implementing pager functionality with a page size of 10. However, I am unable to see the page up and page down buttons ...

Removing a field from a collection using firebase-admin: Tips and tricks

I currently have a collection stored in Firebase Realtime Database structured like this: https://i.sstatic.net/jNiaO.png My requirement is to remove the first element (the one ending with Wt6J) from the database using firebase-admin. Below is the code s ...