Selenium EventFiringWebDriver JavaScript: There is a SyntaxError due to a missing closing parenthesis after an argument in

Attempting to run a javaScript command through the EventFiringWebDriver class in Selenium.

EventFiringWebDriver eventFiringWebDriver = new EventFiringWebDriver(driver);
eventFiringWebDriver.executeScript("document.querySelector('[ng-reflect-title='Assessment']>div.cc-tile>div.cc-tile-body').scrollTop=370");

Encountering an error: Runtime.evaluate threw exception: SyntaxError: missing ) after argument list

If I use the lengthy css selector provided by Chrome for this element:

body > bb-root > best-app > div > div.cc-content > bb-best > bb-assess > best-tile > div > div

instead of:

[ng-reflect-title='Assessment']>div.cc-tile>div.cc-tile-body

The code works without any issues. Both selectors return a single object when tested in Chrome Dev Tools. Using the more dynamic selector is preferred.

Answer №1

Take a look at the JavaScript code you're attempting to execute. Can you spot the issue with Stack Overflow's code highlighting assistance?

document.querySelector('[ng-reflect-title='Assessment']>div.cc-tile>div.cc-tile-body').scrollTop=370

Pay attention to how the word Assessment is colored.

You've placed a string literal within another string literal without properly escaping the quotes, causing the JavaScript compiler to interpret the string ending before Assessment. To resolve this, consider using double quotes instead of single quotes for one set of quotes or escape the inner quotes.

The complexity arises from the fact that this JavaScript snippet with nested string literals is embedded within a Java string literal.

One simple solution is to use escaped double quotes within your JavaScript string for one pair of quotes. In this case, I chose to do so for the outer quotes:

eventFiringWebDriver.executeScript("document.querySelector(\"[ng-reflect-title='Assessment']>div.cc-tile>div.cc-tile-body\").scrollTop=370");

Another option is to escape the inner quotes in your JavaScript code, resulting in the following corrected version:

document.querySelector('[ng-reflect-title=\'Assessment\']>div.cc-tile>div.cc-tile-body').scrollTop=370

However, this approach can become messy as you would need to escape the backslashes in your Java string to ensure they are passed on to JavaScript for escaping the single quotes. Handling multiple levels of character escapes can be confusing, so it's best to avoid this scenario.

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

Issue: "TypeError: Unable to retrieve dynamically imported module" encountered while utilizing dynamic imports in Remix application

I am currently facing an issue with dynamic imports in my Remix application. Whenever I try to dynamically import a module using the code below: const module = await import(../lib/lang/lang-${language.toLowerCase()}.js); An error occurs: TypeError: Fail ...

The div element fails to display even after invoking a JavaScript function to make it visible

As a newcomer to JavaScript & jQuery, please bear with me as I ask a very basic question: I have created the following div that I want to display when a specific JavaScript function is called: <div id='faix' class="bg4 w460 h430 tac poa ...

Show specific elements in a listview using JavaScript

I have created a dynamic listview using jQuery Mobile that currently shows 4 list items. The list is generated through JavaScript. $( document ).ready(function() { var data = [{ "name": "Light Control", "category": "category", "inf ...

Why is the defaultDate property not functioning properly in Material-UI's <DatePicker/> component with ReactJS?

I recently implemented the <DatePicker/> component from Material-UI ( http://www.material-ui.com/#/components/date-picker ) in my project. I encountered an issue while trying to set the defaultDate property to the current date on my computer, as it r ...

The Chromedriver has been lingering on the page for an extended period

Trying to work with a massive page using selenium and Chromedriver has posed a major challenge. The test gets stuck for over two hours after the navigation occurs and the page is loaded. Chrome ends up consuming 100% CPU during this operation, leading me t ...

Convert individual packages within the node_modules directory to ES5 syntax

I am currently working on an Angular 12 project that needs to be compatible with Internet Explorer. Some of the dependencies in my node_modules folder are non es5. As far as I know, tsc does not affect node_modules and starts evaluating from the main opti ...

Is it really necessary to still think poorly of JavaScript in 2011?

Here's an intriguing question for you. I've tested out a variety of popular websites, including Facebook, and I've noticed that many features still work perfectly fine even when JavaScript is disabled. People always used to say that JavaScr ...

Effective methods for accessing and updating text editor values using Selenium

I am currently working on a web page that has a text editor, and I need to populate its value using Selenium scripting in C#. I have successfully done this for a textbox following instructions from Set value in textbox. However, when attempting the same pr ...

Guide on waiting for an asynchronous function in the constructor in JavaScript

In the process of creating a JS class, I encounter a situation where I need to call wasmFunc in the constructor and store its output in this.val. However, since wasmFunc comes from a WebAssembly file, it is necessary to execute an async function called loa ...

Javascript will not be utilized in version 3.8

I'm encountering a problem with the website . It seems like my javascript files are not functioning properly. I added them in the functions.php using wp_enqueue_script(). The browser inspector confirms that the correct files are being called, but the ...

How to retrieve the correct instance of "this" from a callback function within an array of functions nested inside an object

Trying to access the "helperFunction" from within a function in the "steps" array has been quite challenging. It seems that using "this" does not point to the correct object, and I have been struggling to find the right solution. const bannerAnimation = { ...

JSONP request resulted in a syntax error

I'm having trouble retrieving data from a JSONP source, as it keeps throwing a Syntax error when the function is called. I am quite new to this subject and find it hard to understand why this error occurs. It seems like my understanding of JSONP reque ...

Creating simple Java programs utilizing the Selenium WebDriver

As a beginner Java programmer looking to familiarize myself with Selenium libraries, I have been searching Google for a good resource to learn basic Selenium programming. Despite my efforts, I have not been able to find the right place to start. Can anyone ...

The React functional component fails to update when triggered by a parent component's setState method

My React component is utilizing apollo to fetch data through graphql class PopUpForm extends React.Component { constructor () { super() this.state = { shoptitle: "UpdateMe", popupbodyDesc: "UpdateMe" } } re ...

Testing the speed of the client's side

In my quest to create an application that allows users to conduct a speedtest on their WiFi network, I have encountered some challenges. While standalone speedtest apps like Speedtest.net and Google exist, server-based speed test modules from NPM are not s ...

Entry Points for Logging In

After stumbling upon this pre-styled Material UI login page example, I decided that it was exactly what I needed. However, I ran into an issue when trying to figure out how to store the username and password values. Whenever I try to use 'State' ...

Experiencing difficulties loading Expo Vector Icons in Nextjs

I've spent countless hours trying various methods to accomplish this task, but unfortunately, I have had no luck so far. My goal is to utilize the Solito Nativebase Universal Typescript repository for this purpose: https://github.com/GeekyAnts/nativ ...

web browser editing tool

Do you know which library was utilized to create this JSON editor? You can find it at . The editor efficiently checks the syntax and shows errors when necessary. ...

Verifying a parameter from a request URL using Selenium - A step-by-step guide

I found myself on the following webpage: http://localhost:8080/login?error=true How do I verify if the error variable contains the value true? https://i.stack.imgur.com/F5TkF.png This is what I have tried so far and failed: https://i.stack.imgur.com/3 ...

Having trouble showing images from block content using PortableText?

It's been quite a while now that I've been stuck on this issue. Despite being in a learning phase, I find myself unable to progress due to this specific problem. While links and text elements are functioning properly, I have encountered difficul ...