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);