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

"Convert a date string to a date object using the verbose moment date

I utilized the materialize datepicker to select a date in French format. Now I need to convert this formatted date back to a date object for use in my API. Here's how I attempted to revert the date to a standard format: moment("dimanche 30 juillet 20 ...

Enhancing DataTable Performance with Django Filters

I have implemented a feature where users can apply filters to customize the data displayed in a Table. When a user interacts with these filters, an asynchronous Ajax call is triggered: $.ajax({ url: '/fund_monitor/fund_directory&a ...

Animate images using mouse vertical movement

Creating websites is just a hobby for me, not something professional. Recently, I came across a beautifully designed website that had some unique features I hadn't seen before, like placing three images in one div (which I researched and learned how t ...

Urgent concern: the require function is being utilized in a manner that prevents the static extraction of dependencies [mysterious]

After implementing the magic-sdk version 8.0.1 on my project, I encountered the following warning message: warn - ./node_modules/magic-sdk/dist/es/index.js Critical dependency: require function is used in a way in which dependencies cannot be statically e ...

Why is it not possible to isolate the function for xmlHttp.onreadystatechange?

The JavaScript file named test.js is functioning properly when included in my HTML. function sendData() { var formData = new FormData( document.querySelector("form") ); var xmlHttp = new XMLHttpRequest(); xmlHttp.open("post", "test.php",true); ...

What is the best way to adjust the specific scope of every element generated by ng-repeat within a directive?

Attempting to simplify tables in Angular, I am working on a directive. My goal is for the user to only need to provide the list object and the formatting of each list element in the HTML, using the my-table tag as shown below... <h3>My Table</h3& ...

Using Material UI with Reactjs for Background Image Mapping

I need some advice from everyone. I have an array of images and I've mapped the content, but for some reason I am unable to set a background image in the styles of a component. The other objects in the array are working as expected. {DlCards.map((mdlc ...

Ways to incorporate services into functions within Angularjs

I'm struggling to grasp the concept of dependency injection in AngularJS. Currently, I am attempting to inject $interpolate and $eval into my controller. However, after consulting the documentation, I realized that my lack of foundational knowledge i ...

The issue of jQuery not loading within Ajax content has been resolved

Appreciate the assistance provided. I am facing an issue where my jQuery code does not load within ajax content. Below is the code snippet from index.html : <script language="javascript" type="text/javascript"> $(function() { $("#gps").load("find. ...

AngularJS directive: handling child elements

Is there a way to structure the directive below in order to have access to all the ul elements within the link function? In the code snippet provided, when examining the elm (logged in console), it appears as a comment type and ul are displayed as sibling ...

How can I arrange a specific array position in Vuejs according to the Id value?

<div v-for="(item, index) in gr" :key="space.id" class="val-name"> </div> After making a few modifications to the API call logic, I was able to achieve my desired outcome. However, the issue lies in the fact that ...

Validation of HTML forms through JavaScript

I'm working on form validation and struggling with implementing preg_match check from a variable. Currently, I can validate empty fields successfully, but that's not sufficient. Any suggestions on how to proceed? var pattern = /([a-zA-Z0-9]|[a-z ...

Is it possible to bring in Node's path module by using the import statement like this: `import path from 'path'`?

My preference lies with using the import x from 'y' syntax, however, all that has been brought to my attention online is the usage of const path = require('path'). I am curious if there exists a method of importing the path module util ...

Tips for conducting a simultaneous test on several devices

Struggling to execute a single test script on multiple devices, regardless of efforts. There is one test apk and script obtained from a website as a sample. The script locates a textbox in the application, enters "Hello World!" into it, then completes the ...

When attempting to access http://localhost:3000/highLightTitle.png using Next.js, a 404 error (Not Found) was encountered in the content

Despite not having any mention of GET http://localhost:3000/highLightTitle.png in my Next.js project code, I am encountering an error related to this issue. The error can be viewed here, and specifically at line 199 in content.js which can be seen here. T ...

An issue has been identified where the Export to Excel and PDF functionality is not functioning properly within a Datatable after applying a

I am using multiple select option filtering with ajax, jQuery, and PHP in a datatable. The records are being filtered correctly, but after changing the select option, the Export to Excel/ PDF functionality is not working properly. Note:- (1) It always do ...

Having trouble resolving the issue of connection timeout with Chrome while utilizing chrome version 78 alongside chrome driver version 78.0.3904.70? Here's a step-by-step guide on how to troubleshoot and fix this error

After updating my Chrome browser to version 78, I encountered an error when trying to run any automation code. To resolve the issue of timeout while connecting to ChromeDriver and related test frameworks, ensure that ports are protected from access by mal ...

Running scenarios in parallel using TestNG

I am facing an issue while trying to execute multiple classes in my project using the testng.xml file. The problem I am encountering is that it opens three separate navigators, one for each class, and runs the tests sequentially - closing each navigator be ...

Issue with sharing on Facebook via direct URI

I'm currently working on implementing an FB share button on my website. When a user clicks on the button (which features the FB image), they are redirected to . I am dynamically setting the URL as location.href through JavaScript, and the URL is autom ...

Having trouble getting the code to properly execute a PHP file when a button is clicked

I'm facing an issue with a button on my page. When I click on the button, jQuery-AJAX is supposed to execute PHP code from another file, but it's not working as expected. The button's code is very simple: <button type="submit" onclick=" ...