Encountering an issue when trying to execute a JavaScript script using capybara/selenium in a Ruby environment

As a beginner in the world of Automation, I am utilizing Selenium, Ruby, and Capybara to execute this JavaScript script. However, I encountered an error message that says: "Selenium::WebDriver::Error::UnknownError: unknown error: Runtime.evaluate threw exception: SyntaxError: Invalid or unexpected token". Any help on resolving this issue would be greatly appreciated. Thanks in advance.

Below is the snippet of the script causing the error:


function renderField($el, mode) {
  var limitMet,
      field = $el.data(\'add-field\'),
      section = $el.data(\'section\');

  window.DADI.editor.freeSections.forEach(function(freeSection) {
    if (section === freeSection.name) {
        freeSection.fields.forEach(function(sectionField) {
          if(field === sectionField.source) {
              var count = $(\'#section-\' + section).find(\'[data-field="\'+field+\'"]\').length;
          if (sectionField.max && count >= sectionField.max) {
              limitMet = true;
          }
          }
          }.bind(this))
          }
          }.bind(this))

          // More code here...

                function simulateDragAndDrop(source, target)
                {
                    var $clone = source.clone();
                $(target).prepend($clone, target);
                if ($clone.hasClass(\'dadiCells-library__element\')) {
                    renderedHtml = renderField($clone, \'none\');
                $clone.replaceWith(renderedHtml);
                }
                }

                var source = $($(\'.dadiCells-library__element\')[1]); #E.g. The hero video button
                var target = $(\'#section-hero\'); #The target drop zone.
                    simulateDragAndDrop(source, target);

Answer №1

I encountered a comparable problem and found a solution by substituting single backslashes / with double backslashes //

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

Exploring the properties of a file directory

As I try to access the d attribute of a path that was generated using Javascript, the output of printing the path element appears as follows: path class=​"coastline" d="M641.2565741281438,207.45837080935186L640.7046722156485,207.0278378856494L640.698 ...

Retrieve GET ajax requests from a webpage by simply entering the URL

Here's an example from the API I'm currently working with: This particular page relies heavily on GET calls to load most of the data. Three main calls that catch my interest are: All these calls share a common feature, which is the numeric ID ...

Accessing the index in an Angular ngFor loop allows for

Is there a way to access the index within ngFor in Angular? Check out this link for more information. Appreciate any help! Thank you. ...

Uploading images simultaneously while filling out a form

Currently, I have a form that requires users to fill it out and upload an image. However, there is a delay of up to 30 seconds when the user hits "Submit" due to the image size being uploaded. I'm interested in finding a way to initiate the image upl ...

Set the background of the vue widget to be completely see-through

I have a project where I am creating a widget using Vuetify, and embedding it into another website in the following way: <!DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href="component-styl ...

Shape with a dark border div

Having some trouble with creating this particular shape using CSS border classes. If anyone can assist in making this black box shape using Jquery, it would be greatly appreciated. Check out the image here. ...

Is there a way to modify the spacing between labels and text in the TextBox MUI component while using custom label sizes?

https://i.sstatic.net/OvAN9.png I've customized a material ui TextField component by increasing the font size of the label. However, I'm facing an issue where the gap in the border for the label remains unchanged despite the larger text size. I ...

Send key-value pairs to the function using ng-model

I am currently working on a functionality that involves extracting an object from json and displaying its key-value pairs using 'ng-repeat' in AngularJS. The form includes checkboxes where the value can be either true or false, determining if the ...

What could be causing this error message: selenium.common.exceptions.StaleElementReferenceException?

Although I have already uploaded an answer to this same question, the solutions provided did not work for me due to recent updates in the Selenium code. selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is ...

JMETER and Selenium WebDriver are experiencing issues with executing multiple threads efficiently

Currently, I am attempting to execute a test for 5 - 10 users using WebDriver Sampler within JMeter. I have successfully configured Chrome Driver and included the necessary WebDriver Sampler code. Interestingly, when running the test for only 1 user, every ...

Utilizing Object Assign to reset the state

Here lies the declaration of my current state: export default new Vuex.Store({ state: { items: [ ], user: { isAuthenticated: false, info: { createdAt: '', email: '', firstName: '&a ...

Issue with Element's Response to JQuery Click Event

After pulling elements from the database in PHP, I utilized Jquery to add Elements to the page. Each button has two classes; one for controlling the GUI and another for handling the click event of that specific button. Here is the code snippet: echo " ...

What is the method for inputting text into a textbox during automation testing?

I am currently testing out c# with selenium on the website . One of the first steps is to log in to the site. To do this, I located a button named "Вход" in the top right corner using xpath and clicked on it. After the page refreshed and changed, the ...

Creating markers for every value in a table using Google Maps API v3

Looking for some guidance here. I have a table with multiple values that I need to process using a function. Could someone help me with a suitable loop in jQuery or JavaScript that can achieve this? I'm still learning the ropes of these languages. My ...

Selenium tests encountering failures on a remote server with Chrome and Internet Explorer drivers

Currently, I am utilizing Selenium Grid in conjunction with TestNG for distributed testing purposes. My aim is to execute tests on remote machines using the Chrome and IE browsers. Unfortunately, I have encountered exceptions when running these tests on sa ...

When typing in the textarea, pressing the return key to create a line break does not function as expected

Whenever I hit the return key to create a new line in my post, it seems to automatically ignore it. For example, if I type 'a' press 'return' and then 'b', it displays 'ab' instead of 'a b'. How can I fi ...

jQuery AJAX event handlers failing to trigger

It's driving me crazy! I've been using jquery's ajax for years, and I can't seem to figure out why the success, error, and complete events won't fire. The syntax is correct, the service it's calling works fine, but nothing hap ...

Having trouble receiving a JSON array after making an Ajax request

I have read through previous posts on this issue, but I still can't seem to figure it out. Hopefully, someone here can help me solve this problem. My challenge lies in retrieving an array, which I have encoded in json, from a PHP script and passing i ...

Run a series of promises in an array one after the other without relying on async and await

Imagine having an array filled with promises. Each element in this array represents a knex.js query builder that is prepared to be executed and generates a promise. Is there a way to execute each element of this dynamically built array sequentially? let ...

displaying several gltf 3D models simultaneously on a map using mapbox gl and three js

Recently, I encountered an issue with adding glTF 3D models to a map using Mapbox GL and Three.js. It seems that while I can successfully add a single glTF model in a separate layer on the map, I am facing difficulties when trying to add multiple glTF mode ...