What could be the root cause behind this Selenium mistake?

My goal is to verify the correct scroll position in the browser using NightwatchJS and Selenium. Below is the command I am using in Nightwatch:

assertScrollPosition(testValue) {
            this.api.execute(() => {
                const offsetValue = window.pageYOffset;
                return offsetValue;
            }, [], (result) => {
                console.log(result);
                this.assert.equal(
                    testValue,
                    result.value,
                );
            });
        },

Initially, everything was working fine with this test. However, something changed recently and now the result object is throwing an error:

{ status: -1,
  value:
   { additionalInformation: '\nDriver info: org.openqa.selenium.chrome.ChromeDriver\nCapabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, ...chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=}]\nSession ID: 56606c23e68c130649c1efa3573c3122',
     localizedMessage: 'unknown error: cov_1qa0joknhz is not defined\n  (Session info: chrome=66.0.3359.117)\n  (Driver info: chromedriver=2.36.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8),platform=Mac OS X 10.11.6 x86_64) (WARNING: The server did not provide any stacktrace information)\nCommand duration or timeout: 9 milliseconds\nBuild info: version: \'2.53.0\', revision: \'35ae25b\', time: \'2016-03-15 17:00:58\'\nSystem ...
...

Answer №1

The variable cov_1qa0joknhz is not found within the browser environment. It seems to be a variable injected by a code coverage tool such as Istanbul. To solve this problem, you can inject your code as a string:

this.api.execute("return window.pageYOffset;", ...

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

Vue.js methods bound as properties on a parent object

There are times when I come across scenarios where it would be convenient to bind methods as an object property rather than a direct Vue method. For instance, instead of: <MyInput :formatter="currencyFormat" :parser="currencyParser& ...

Preserving Firefox Cache and History Files with Selenium

Is it possible to prevent Selenium from creating a temporary directory and profile when launching Firefox? While I understand the reasons behind Selenium's default behavior, I am currently exploring ways to utilize it for generating Firefox caches an ...

Waiting for an element in Selenium until it is both visible and ready to be interacted with

Currently, I am using a Python Selenium script that clicks on a reply button in order to reveal the anonemail class. The timing of when the anonemail class appears can vary, so I have resorted to using sleep to wait until the element is displayed. However ...

Troubleshooting Problem with Angular JS Page Loading on Internet Explorer 9

My angularjs single page application is encountering issues specifically in IE9, despite functioning perfectly in Chrome and Firefox. The initial load involves downloading a substantial amount of data and managing numerous dependencies through requireJS. ...

The Iframe is preventing the mousemove event from taking place

After attaching an event to the body, a transparent iframe mysteriously appeared in the background of the popup. I am attempting to trigger a mousemove event on the body in order for the popup to disappear immediately when the mouse moves over the iframe ...

What is the best way to display JavaScript in a view in ASP.NET MVC 3?

Good day Everyone, I am currently facing an issue with a javascript variable in my view. This is what I have been trying to do... var skinData = null; and then, when the document is ready.... $.ajax({ type: 'POST', ...

"Enhance your website with autocomplete feature using the power of jQuery 1.4.2 and jQuery UI 1

Struggling to make jQuery autocomplete work. Despite searching for examples, most seem outdated. Modeled after a good example from the jQuery UI site but still can't get it to display data. My JSON data source is accessed via URL. [{ "pk": 1, "mo ...

Tips on creating adaptable images for mobile viewing

My coding conundrum involves the use of two columns - one for an image and the other for a description of that image. However, when viewing my site on mobile devices, the image is cut off at only half its height. Adjusting both columns to col-sm-6 results ...

What is the reason for create-react-app initializing twice?

After creating a react app using the command npx create-react-app, I encountered an issue: import React from 'react'; class Costly { constructor() { console.log('creating costly class'); } } function App() { const costlyRef ...

Detect the "@" character through keyUp for the implementation of @mentions feature

I am currently working on implementing an @mention feature using Vue and Vanilla JS, but I am facing issues with targeting the "@" character specifically. Within my template: <trix-editor ref="trix" @keyup="listenForUser" ></trix-editor& ...

Is there a way to find keys with matching values within a dictionary?

In my dictionary, I have two sets of identical array values for different keys. My query is: How can I determine which keys have the same value based on inputting just one value? I want to retrieve all keys that share the same values as an output. This i ...

Can you explain the distinction between "javascript:;" and "javascript:" when used in the href attribute?

Can you explain the distinction between using "javascript:;" and just "javascript:" within an anchor tag's href attribute? ...

Error alert: The system could not locate Google when trying to drop pins

Every time I attempt to place pins on the map, I encounter the "google is not defined" error. The map itself displays without any issues until I add the lines following the initMap() function. I have come across similar posts but none of the suggested so ...

How do I verify the presence of an attribute using Webdriver?

My goal is to confirm that a specific "ID" includes an attribute of "hidden". This "hidden" attribute won't actually have a value; it will be present if I've clicked on a certain button and absent if I haven't. Here's the code snippet: ...

Encountering the error message "Unable to access property 'addEventListener' of null while trying to manipulate innerHTML"

Currently, I am utilizing innerHTML to include certain elements and a wrapper around them. for (i = 0; i < arr.length; i++) { b.innerHTML += "<div class='wrapper'><div class='col-4'>" + arr[i].storeID + "</div> ...

Utilizing JavaScript Classes to Implement Multiple CKEditor Instances

I have been attempting to utilize CKEDITOR for editing the content on my website. However, I am unsure about how to handle multiple instances of CKEDITOR. I have encapsulated all the JavaScript functions in a Class, but I need assistance in determining whi ...

Retrieving all buttons from a webpage and removing those with a specific background-image using JavaScript

Hey everyone, I'm still learning about javascript and other web development languages. My current task is to locate all the buttons on a webpage and remove the ones that have a specific background image. I know about using getElementsByTagName but n ...

Issue found: Passing a non-string value to the `ts.resolveTypeReferenceDirective` function

Encountering the following error: Module build failed (from ./node_modules/ts-loader/index.js): Error: Debug Failure. False expression: Non-string value passed to ts.resolveTypeReferenceDirective, likely by a wrapping package working with an outdated res ...

Implementing CSRF token for the current window's location

Is there a way to add a CSRF token to all instances where window.location.href is used in my Javascript code? It's not possible to override the window.location object and its properties like window.location.href. Creating a universal function to inc ...

How can I convert a string containing integers into an int[] using javascript or jQuery?

I want to create a feature that allows users to input a list of IDs in a textarea, with the option to separate them by either whitespace or commas. After the user inputs the list, I need to convert it into an int[] array but also throw an error if the str ...