An error occurred in the main thread while using Selenium with Java and JavaScript: "Exception in thread "main" org.openqa.selenium.JavascriptException: missing ) after argument list"

While testing in Chrome's developer tools console, I successfully executed the following codes. However, when attempting to run them in Selenium, an error stating "missing ) after argument list" was encountered. This issue suggests incorrect syntax, but the reason behind it remains unclear. It is important to note that each attempt was conducted independently.

//Modified Attempt 1
JavascriptExecutor js = (JavascriptExecutor)driver;    
        js.executeScript( "var evt = document.createEvent('MouseEvent');" +
        "evt.initMouseEvent('mousedown', true, true, window, 0, 0, 0, 382, 290 , false, false, false, false, 0, null);" +
        "var cb = document.getElementById('gameCanvas');"+
        "cb.dispatchEvent(evt);"+
        "setTimeout(function(){"+
        "evt.initMouseEvent('mouseup', true, true, window, 0, 0, 0, 382, 290 false, false, false, false, 0, null);"+ 
        "cb.dispatchEvent(evt);}, 100); };"); 

//Revised Attempt 2 
      JavascriptExecutor js = (JavascriptExecutor)driver;   
        js.executeScript( "var evt = document.createEvent('MouseEvent');" +
        "evt.initMouseEvent('mousedown', true, true, window, 0, 0, 0, 382, 290 , false, false, false, false, 0, null);" +
        "var cb = document.getElementById('gameCanvas');"+
        "cb.dispatchEvent(evt);"+
        "evt.initMouseEvent('mouseup', true, true, window, 0, 0, 0, 382, 290 false, false, false, false, 0, null);"+ 
        "cb.dispatchEvent(evt);");

Answer №1

Teemu pointed out that in both attempts, the second line of evt.initMouseEvent is missing a comma between 290 and false.

Furthermore, there is an extra "};" after the "100);" statement.

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

Having trouble getting haxe-pixi.js to function properly as it only shows a blank white screen

***UPDATE: Success! Managed to solve the issue. It turns out the missing library in the html file was causing the problem. The pixi.min.js file was not present in the haxelib directory, which seems a bit unusual. Here's a more challenging question: i ...

Creating a sleek horizontal drop-down navigation menu using Bootstrap 5 and CSS

Attempting to design a horizontal dropdown menu for small screens has been a challenge. However, all the resources I've come across seem to be outdated and ineffective. ...

Instructions on converting XML data obtained from an AJAX call into a downloadable file

I've been struggling with converting an AJAX response containing XML text into a downloadable file. I've tried various methods but haven't had success. In the past, I was able to work with a similar scenario involving a pdf, where the conte ...

Utilizing Selenium to extract an Integer from a table cell

<td class="v-grid-cell numerical" style="height: 22px; width: 94px;" colspan="1">32942025</td> This particular snippet of HTML code relates to the question at hand. My objective is to extract the numeric value 329 ...

Having a problem with configuring the request headers for my AJAX request

Currently, I am attempting to initiate an ajax call to a service. The service API requires a Request Header for Authorization in order to provide a response. Below is the code snippet that I am using: var settings = { url: "http://localhost:8080/c ...

Adding additional validations to your Marketo form is a great way to ensure the accuracy

I'm having trouble adding a new validation rule to the Marketo form since I'm not well-versed in JS and jQuery. I need this rule to display an error message if the form is submitted with any field left empty. Additionally, I want to validate the ...

A method for navigating between <DIV> elements nested within each other using Selenium

Attempting to interact with a button nested within multiple DIV elements, the following HTML is provided: <div class="chat-message-container ngi bot" chat-msg-id="EzPtItD3exi2lTGS3SQkV0-h|0000016" chat-msg-text="What is the intended purpose of your inv ...

Implementing a verification prompt prior to removing a data entry from the database

Can someone help me troubleshoot an issue I'm having with a confirmation screen? I am trying to display a confirmation screen before deleting a value from my database. The pop-up screen should appear when clicking on an icon or button. However, I am ...

Guide on invoking a function in a PHP file using jQuery's load method

I am having trouble displaying the data retrieved from the database. There is a function called "getComments(page)" in the getComments.php file, where 'page' is an integer parameter corresponding to the chosen database. I need to call this functi ...

Unable to show the total number of rows in a table depending on the selection from a drop-down menu or input field

Currently, I have a table with a variable number of rows, but it is set to display 10 rows in each page by default since the table is paginated. Now, I am working on adding a text box where users can input the number of rows they would like displayed on e ...

Spring controller is malfunctioning when the final PathVariable in the RequestMapping is empty

Having issues mapping a request to my Spring controller Encountering a 404 error when trying /simple/test/something/..... with the following mapping: @RequestMapping(path="/simple/test/{string1}/{string2}") Snippet of code: @RequestMapping(path = "/sear ...

transfer scope variable to scope function

I notice this pattern frequently view: <input ng-model="vm.model"> <button ng-click="vm.method(vm.model)"></button> controller: function Controller() { var vm = this; this.method = function(parameter) { // perform acti ...

I'm having trouble understanding why I can't access the properties of a class within a function that has been passed to an Angular

Currently, I have integrated HTML 5 geolocation into an Angular component: ... export class AngularComponent { ... constructor(private db: DatabaseService) {} // this function is linked to an HTML button logCoords(message, ...

Achieving nested routes without the need for nested templates

My Ember routes are structured like this: App.Router.map(function() { this.resource("subreddit", { path: "/r/:subreddit_id" }, function() { this.resource('link', { path: '/:link_id'} ); }); }); However, ...

The Date column in a JTable is read-only and cannot be modified

I am currently working on a Java desktop application using NetBeans 8.0. In this project, I have implemented a JTable with a custom table model. Everything works well except for one issue - I am unable to edit the column that contains Date data type values ...

`Is it necessary to handle textStatus when encountering an HTTP error during an AJAX request?`

When utilizing jQuery and encountering an AJAX request failure attributed to an HTTP error (e.g., 500 Internal Server Error), what exactly is the assigned value of the textStatus parameter within the error handler function? For instance, $.ajax(...).fail( ...

Reordering the elements in a Java list by moving the initial word to the end

I've been attempting to rearrange the words in a sentence by moving the first word to the last position using Java. However, my program is not successfully printing the modified sentence. What could I be overlooking? Below is the code I have written: ...

Typing text into a text box using Python Selenium

I am currently working on a project that involves submitting Google Forms, and I am encountering issues with the textfield-type questions. This is how I am approaching it: textfield = question.find_element_by_class_name("quantumWizTextinputPaperinputI ...

Python: Running multiple instances of Selenium simultaneously

Is it possible to concurrently run several instances of selenium? My approach involves utilizing APScheduler to schedule functions for execution, with each function requiring its own selenium instance. Any assistance would be greatly appreciated. ...

Angular directive does not focus on the text box

I've been working on creating text boxes using a directive and I want only the first text box to be in focus. To achieve this, I am utilizing another directive for focus control. Below is my script: <script> angular.module('MyApp',[]) ...