Jasmine is having trouble scrolling the window using executeScript

I usually use the following command:

browser.driver.executeScript('window.scrollTo(0,1600);');

However, this command is no longer working.

No errors are showing in the console, making it difficult to troubleshoot.

Interestingly, the same script works for another test case but I cannot identify any differences between them.

As a solution, I attempted to use scrollIntoView which resulted in an infinite loop.

Full test case:

describe('My business page ', function() {

    var EC = protractor.ExpectedConditions;
    var loginBox = element(by.css("div.info-box.client-login.ng-scope"));
    var centerElm = $$(("div.action-extra-content.wysiwyg-content.ng-binding.layout-column")).first();
    var scrollIntoView = function (element) {
      arguments[0].scrollIntoView();
    };

    beforeEach(function() {
      browser.ignoreSynchronization = true;
    });

    afterEach(function() {
      browser.ignoreSynchronization = false;
    });


  it('Main page - Top', function() {
    browser.get('https://live.vcita.com/site/bungee');
    browser.wait(EC.visibilityOf(loginBox), 30000);
    browser.driver.sleep(5000);
  });

  it('Main page - Center', function() {
      browser.executeScript(scrollIntoView, centerElm);
      console.log("Scroll me!!!")
      browser.driver.wait(EC.elementToBeClickable(centerElm),30000);
      browser.driver.sleep(2000);
  });

});

Error:

 RangeError: Maximum call stack size exceeded
   Stacktrace:
     RangeError: Maximum call stack size exceeded
    at Function.childCtor.base (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\base.js:2163:38)
    at promise.Callback_.goog.defineClass.constructor (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:2431:23)
    at new wrappedCtr (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\base.js:2366:26)
    ...

Answer №1

If the container you are trying to scroll is not the window or document, in order to run a script with a specific element, you must pass the native element returned by .getWebElement():

var elm = $('...');
browser.executeScript(function(element){
    element.scrollIntoView();
}, elm.getWebElement());

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 navigating the material ui Expanded attribute within the Expansion Panel

After looking at the image provided through this link: https://i.stack.imgur.com/kvELU.png I was faced with the task of making the expansion panel, specifically when it is active, take up 100% of its current Div space. While setting height: 100% did achi ...

Request made to Ajax fetching complete webpage content

I have a page full of random tips at http://www.javaexperience.com/tips To display these tips on other pages of the website, I am using an ajax call to add the content returned by the call to a specific div's HTML. The code for the div is: <div ...

Exploring the power of Selenium Webdriver in combination with JavaScript

Can someone help me figure out why I'm getting this error message: "Exception in thread "main" java.lang.ClassCastException: java.lang.Long cannot be cast to org.openqa.selenium.WebElement at canvasdrag.Canvas.main(Canvas.java:57)" WebElement elemen ...

Guide to transferring req.params to a callback function within node.js

I am currently working on a Node.js project using Express. I have been attempting to retrieve data using the NPM request package, utilizing a specific URL and passing an anonymous callback function to handle the resulting JSON file. The code below has bee ...

Similar items with diverse Xpath configurations

My current challenge involves scraping all the comments from a website. The issue lies in the fact that some comments have varying XPath structures. For instance: Item 1: //*[@id="__next"]/div[1]/main/div[3]/div[4]/div/div[2]/div[3]/div[2]/div[3 ...

What is the process for executing Express's scaffold by utilizing "nodemon" and the basic "node" command instead of relying on the "npm start" command?

Could you help me locate where I need to make changes in my package.json file? Here is the content of my package.json: { "name": "xyz", "version": "0.0.0", "private": true, "scripts": { "start": "node ./bin/www" }, "dependencies": { ...

The Holy Alliance of Laravel and Vue

I am facing issues with user authentication using Laravel Sanctum. I have set up everything properly, with Vite and Vue 3 as the frontend. The problem arises when I attempt to login with Laravel's default auth - it works fine. However, when I make a r ...

Troubleshooting problem with generating email-friendly reports in TestNG

I've successfully developed a Java method for sending emails with an attached TestNG emailable report. The email and report are being sent to the designated email address without any issues. However, I have encountered a problem where I am calling th ...

CORS headers present but AJAX request still fails

A request sent via AJAX from a locally hosted page to a remote server is encountering errors, despite the presence of CORS headers. The JavaScript code for this request is as follows: $.ajax({url: 'http://prox.tum.lt/420663719182/test-upload?Action=S ...

Encountering difficulties in loading my personal components within angular2 framework

I encountered an issue while trying to load the component located at 'app/shared/lookup/lookup.component.ts' from 'app/associate/abc.component.ts' Folder Structure https://i.stack.imgur.com/sZwvK.jpg Error Message https://i.stack.img ...

Display Image After Uploading with AJAX

After spending nearly 3 hours working on implementing file uploads via AJAX, I have finally managed to get it up and running smoothly. Take a look at the code below: View <div class="form-horizontal"> <div class="form-group"> @Htm ...

Reading an XML file to locate items nested within the same bracket

Within my JavaScript function, I am utilizing the following code to extract data from an XML file: var title = $(this).children('Title').text(); This snippet of code successfully retrieves the content under the <Title> tags: <Title> ...

Checking the validity of a JSON file extension using regular expressions

Using EXTJS, I have created a file upload component for uploading files from computer. I need to restrict the uploads to JSON files only and want to display an error for any other file types. Currently, I am able to capture the filename of the imported fil ...

using selenium webdriver to dynamically retrieve table data

<table id="tblListViewHeader" class="adminlist" cellspacing="1" cellpadding="0" style="table-layout: fixed; width: 1003px;"> <tbody> </table> </td> </tr> <tr> <td> <div id="divListView" style="width: 100%; heigh ...

Any tips for filtering an array within an array of objects using the filter method?

I have an array of products and models that I am currently filtering based on 'id' and 'category'. var app = angular.module("myApp", []); app.controller("myCtrl", function($scope) { $scope.products = [{ 'id': 1, ...

Issues with Angular toggle sorting functionality not functioning as expected

$scope.searchObject = { from: 0, hydrate: false, size: 12, sort: 'timestamp:desc' }; $scope.sort = function(a) { var ascend = a + ':' + 'asc'; var descend = a + ':' + 'desc'; if ($scope.searc ...

Navigating through a multidimensional array in Angular 2 / TypeScript, moving both upwards and downwards

[ {id: 1, name: "test 1", children: [ {id: 2, name: "test 1-sub", children: []} ] }] Imagine a scenario where you have a JSON array structured like the example above, with each element potenti ...

Is there a way to dynamically incorporate line numbers into Google Code Prettify?

Having some trouble with formatting code and inserting/removing line numbers dynamically. The line numbers appear on the first page load, but disappear after clicking run. They don't show at all on my website. I want to allow users to click a button a ...

Tips for sending a unique button ID to a jQuery click function

Within a table row of a dynamically generated table, I have multiple buttons each with its own functionality. My goal is to figure out how to pass the specific button ID to the onclick event of that table row when one of these buttons is clicked. $(&apos ...

Utilize jQuery ajax to pull in data from an external website

I've been doing some research on using jQuery ajax to extract links from an external website, but I'm a bit lost on where to begin. I'm taking on this challenge just to push my skills and see what I can accomplish. While reading about the S ...