Encountering a "Can't find variable" error in Java when using Ghostdriver 1.2.1 with PhantomJS 2.0 and the newest version

[ALERT - 2016-01-16T02:22:00.898Z] Session [e6651a90-bbf7-11e5-9061-cff578894101] - page.onError - msg: ReferenceError: Can't find variable: data

:262 in error [WARNING - 2016-01-16T02:22:00.898Z] Session [e6651a90-bbf7-11e5-9061-cff578894101] - page.onError - stack: (anonymous function) (http://www.example.com/ns/common/jquery/jquery.cartActions.js?cd=0:205) o (http://www.example.com/images/common/jquery/jquery.latest.js:2) fireWith (http://www.example.com/images/common/jquery/jquery.latest.js:2) w (http://www.example.com/images/common/jquery/jquery.latest.js:4) d (http://www.example.com/images/common/jquery/jquery.latest.js:4) openUrl (:0) open (:280) (anonymous function) (:/ghostdriver/request_handlers/session_request_handler.js:495) _execFuncAndWaitForLoadDecorator (:/ghostdriver/session.js:212) _postUrlCommand (:/ghostdriver/request_handlers/session_request_handler.js:494) _handle (:/ghostdriver/request_handlers/session_request_handler.js:91) _reroute (:/ghostdriver/request_handlers/request_handler.js:61) _handle (:/ghostdriver/request_handlers/router_request_handler.js:78) :262 in error

^Domain edited out on purpose.

As per information from Can't find variable - PhantomJS, this particular error seems to be related to improper jailed execution of Javascript. The specifics of this issue and its connection to Java programming has left me confused.

In my Selenium program, the Javascript call is fairly simple and goes like:

((JavascriptExecutor) driver).executeScript("arguments[0].click();", buttonToClick);

The above line appears to be functioning correctly as other similar lines execute without any errors before encountering the aforementioned issue.

Even though I have tried several configurations with the PhantomJS driver initializer block below, I have not been able to resolve "acceptSslCerts":false under Session.NegotiatedCapabilities:

String[] cli_args = new String[]{"--debug=false", "--web-security=false", "--ssl-protocol=any", "--ignore-ssl-errors=true"};
        DesiredCapabilities caps = DesiredCapabilities.phantomjs();
        caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cli_args);
        caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "/Users/richard/Downloads/phantomjs-2.0.0-macosx/bin/phantomjs");
        driver = new PhantomJSDriver(caps);

Despite seeing that the arguments are indeed being passed in through the Console...

Jan 16, 2016 6:23:40 AM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: arguments: [--web-security=no, --ignore-ssl-errors=yes, --webdriver=33238, --webdriver-logfile=/Users/richard/YeezyBot/phantomjsdriver.log]

It's worth mentioning that everything runs smoothly with Firefox WebDriver.

Answer №1

Avoid injecting JavaScript into web pages as it is not considered a good practice. Instead, utilize Selenium code to locate and interact with elements on the page without the need for injection.

  1. Ensure that the page has fully loaded

  2. Locate the button using CSS or XPath expressions

  3. Wait for the element to become clickable

  4. Click on the element using only Selenium code

    WebDriverWait wait = new WebDriverWait(driver, timeToWait);

    this.by = by;

    try {

    WebElement lastFoundElement = wait.until(ExpectedConditions.visibilityOfElementLocated(by));

    wait.until(ExpectedConditions.elementToBeClickable(lastFoundElement ));

    new Actions(browser).moveToElement(element, offsetX, offsetY).click().build().perform();

    } catch (Exception ex) {
    }

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

Determining the Existence of Duplicates in an HTML Table with Multiple Inputs Using JavaScript

After spending countless hours on research with no luck, I've finally come to seek assistance from you. In my form, I have an input field and a select field, along with a table generated using PHP from my database that displays team names and their r ...

Issue arises when isomorphic-dompurify is used alongside dompurify in Next.js 13 causing compatibility problems

I am currently facing a compatibility problem involving isomorphic-dompurify and dompurify in my Next.js 13 project. It appears that both libraries are incompatible due to their dependencies on canvas, and I am struggling to find a suitable alternative. M ...

Error: AJAX responseText Mismatch detected

When I make an AJAX call in my code, everything seems to be working correctly. The PHP script responds with "success" when it should, and the response text is indeed "success". However, even though the output appears to be correct, the line if(returnVal == ...

Add several additional views following an element within a View in Backbone

addDimensions: function (order_id, counter) { this.dimensionsView = new dimensionsView({ el: "#panel-boxes-" + order_id + "_" + counter, id: order_id, counter: counter }); $("#panel-boxes-" + order_id + "_1").append(this.dimensionsView.render().el) ...

Leveraging the power of AJAX to dynamically update information on a modal form using PHP's

After successfully preventing my modal form from closing upon submitting a value using ajax jQuery without refreshing the page, I encountered a new issue. Whenever I fill in my modal form and click submit to update the data inside my database, it does not ...

Python for Asynchronous HTTP Requests

I am currently working on a Python script to extract the value of the href attribute from an anchor element on a web page. The challenge is that the div element containing the anchor element's content is loaded through AJAX jQuery calls when the web p ...

Uncaught Node.js Error Event Handling

Hello everyone, I'm new to this and currently working on writing a code that utilizes node's event emitter. Take a look at the code snippet below: var EventEmitter = require('events').EventEmitter; var errors = require('./errors&a ...

Acquiring data from a separate Redux slice and utilizing it as the default state in a distinct slice

In my application, I have two Redux slices called userSlice and cartSlice. My goal is to extract the specific value userName from the userSlice and use it as the initial value for a property named user in the cartSlice. Despite my efforts, I am encounterin ...

A guide to determining the dimensions (width, height, length) of a mesh using THREE.js

I've been scouring different sources in hopes of finding a way to obtain the width and height of a mesh, but I haven't had any luck. I have imported a collada model into my project, and all I need is to determine its dimensions in Webgl/Three.js ...

Click on a link to navigate to a new page using the useNavigate hook in

I have successfully implemented navigation using the useNavigate hook, but I am wondering if there is a way to open the URL in a new tab instead of the current one. Is this achievable? Here's my code: import { useNavigate } from "react-router-do ...

Conflicting TypeScript enum types: numbers and numbers in NestJS/ExpressJS

Incorporating types into my NestJS server has been a priority. After creating a controller (a route for those who prefer Express), I attempted to define the type for params: public async getAllMessages( @Query('startDate', ValidateDate) start ...

What is the process for changing the background color when a button or div is pressed, and reverting the color back when another button or div is

Looking to customize a list of buttons or divs in your project? Check out this sample layout: <button type="button" class="btn" id="btn1">Details1</button> <button type="button" class="btn" id="btn2">Details2</button> <button ty ...

Struggling to convert my VueJS component from JavaScript to TypeScript, feeling a bit lost

I am new to VueJS and I am facing a challenge converting my VueJS project to use TypeScript. I have been trying to bind functions to certain variables in JavaScript, but I am struggling with accomplishing the same in TypeScript. Even though there are no er ...

Troubleshooting a minor JavaScript loop problem

I am facing an issue with my script that retrieves data from a database. Currently, when the search() function is called by clicking a button, only one result is displayed in a new div. How can I ensure that a new div is created for each result found, rath ...

Ways to avoid the browser from storing a JSON file in its cache

Hey there, I'm working on a project and running into some issues with caching. The problem I'm facing is that the browser keeps holding onto the json file containing save data even after I update it elsewhere. This means that the browser is readi ...

In a Vue Application, the static HTML elements are loaded before fetching data

Utilizing VueJS and VueRouter in my application has presented a challenge. The issue lies in the fact that static HTML elements within the Vue Component load before the data is fetched, resulting in empty forms and tables being displayed initially. I have ...

Instructions on how to prompt the testng files to run following user input from the console

I have multiple test suites in my pom.xml file and I would like to prompt the user for input from the console after running each testng suite file in order to trigger the execution of the next testng file in the pom.xml. For example, let's say my pom ...

What is causing Mocha.js to be unable to locate the module?

Having trouble with mocha.js not being able to locate my path! Here's the directory structure I have set up for my node course project: ///////Root --package.json --node_modules/ --playground --server -server.js -db -models ...

The functionality to apply a color class to a navbar item when clicked is malfunctioning

I'm attempting to create a navigation bar using text that toggles the visibility of different divs. I want the selected option to appear in red, indicating it has been chosen, while deselecting any other options. I am new to JavaScript and thought add ...

Show data in a popup using jQuery DataTables and loading content asynchronously via Ajax

I am attempting to display a list in a popup based on an Ajax request. Prior to the Ajax call, the list is contained within the popup. However, after the Ajax request, the list remains on the page instead of inside the popup, and the old list still appears ...