casperjs is encountering difficulty locating the id even after setting it

Issue with CasperJS not locating the ID after setting it

Casper.then(function () {
    screenLog();
    var id =  String("_newid_");
    var arrow = this.evaluate(function () {
        var arrows = document.querySelectorAll('span.select2-selection__arrow');
        arrows[1].innerHTML = "aa";
        arrows[1].id = id;
        return arrows[1].innerHTML;
    });
    screenLog();
    this.click("#"+id);
    screenLog();
});

Error message received: CasperError: Cannot dispatch mousedown event on nonexistent selector: #newid

Answer №1

When using Caspers evaluate method, it operates in a separate environment (DOM environment), meaning that variables defined in the Casper environment are not accessible in the browser environment. However, you can transfer variables to the browser environment by including additional parameters in the evaluate function.

Therefore, if the 'id' is undefined in your situation, you can pass it correctly as shown below:

var id =  String("_newId_");
var arrow = this.evaluate(function (id) {
    var arrows = document.querySelectorAll('span.select2-selection__arrow');
    arrows[1].innerHTML = "aa";
    arrows[1].id = id;
    return arrows[1].innerHTML;
}, id);

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

Is there a way to generate a fresh array by filtering an array of objects based on a single value?

I am currently working with an array of objects: const dummyLinkRows = [ { id: 'entity:link/1:en', categories: [ { name: 'Human Resources' }, { name: 'Social' } ], nam ...

How can you animate the background of a website using AngularJS - CSS or JavaScript?

My aim is to create a dynamic animation for the background image when the view changes. The current background image is set through a function defined within MainController: // app/js/controllers.js $scope.getBg = function() { return $route.current.sco ...

Error encountered while exporting TypeScript module

While I am working with Angular, TypeScript, and Gulp, my module system is CommonJS. However, I encountered an error when trying to import a module into my main.ts file: Error: Cannot find external module 'modules.ts'. Here is the snippet from ...

Guide on linking Influxdb information in a Vue application using node.js?

I have successfully connected my InfluxDB database to my Vue app and can log data in the terminal using the code below: // index.js import express from "express"; // These lines make "require" available import { createRequire ...

What is the best way to trigger the jQuery-File-Upload event within this function?

Before uploading a file, I want to check the API first. $('.file_upload_button_wrapper').on('click', function () { // perform check here $.ajax({ url: '/?app=files&getfile=ajax%2Fupload.php', ...

Struggling to get a shader up and running on three.js using shaderfrom

Trying to add this shader to my project: This is the fragment shader code: <script id="fragmentShader" type="x-shader/x-fragment"> #ifdef GL_ES precision highp float; precision highp int; #endif uniform vec2 u_resolutio ...

Troubleshooting why content set to a <div> element with JavaScript / jQuery is not persisting after a

This is the current code snippet I am working with: <asp:Button ID="btnSave" runat="server" OnClick="Save" CssClass="StylizedButton" resourcekey="btnSave" /> <div id="lbltot"></div> Below is the JavaScript portion of the code: $(do ...

Retrieving data from a radgrid with the power of jQuery

Trying to extract the text from the label GetName in a radgrid using jQuery. Need to iterate through each record to check the value of the label. Can anyone provide assistance? Thanks! Below is the code for my radgrid. <telerik:RadGrid ID="Gridview1 ...

Tips on successfully transferring a JavaScript variable from PHP to JavaScript

I am struggling with how to manipulate a JavaScript variable in my HTML script and then pass it to a PHP file for incrementing by 1. However, I am unsure of how to return this modified variable back to the HTML file for display. Additionally, I am uncertai ...

Sending Image Data in Base64 Format with Ajax - Dealing with Truncated Data

My current challenge involves sending Base64 image data through ajax to the Server. I've noticed that sometimes all the pictures are successfully sent, but other times only a few make it through. Does anyone have suggestions on how to implement error ...

Explication of syntax not functioning

Following the instructions provided here but encountering issues, any assistance? <script type="text/javascript" src="sh/src/shCore.js"></script> <script type="text/javascript" src="sh/scripts/shBrushJScript.js"></script> <lin ...

Employing Modernizer.js to automatically redirect users to a compatible page if drag and drop functionality is not supported

I recently set up modernizer.js to check if a page supports drag and drop functionality. Initially, I had it set up so that one div would display if drag and drop was supported, and another div would show if it wasn't. However, I ran into issues with ...

Guide to building a dual recursion menu in AngularJS using both functional and template methods

I'm currently working on developing a menu in AngularJS using template and functional recursion. The code I have written involves quite a bit of recursion, so I could really use some assistance. Below is the menu data represented in JSON format: var ...

Unexpected misalignment in Watir/Capybara and PhantomJS

Looking to pinpoint the exact location of elements on a page using Watir and PhantomJS, I attempted to use Capybara as well, but encountered the same offset issue. While the alignment of elements on the left side appears correct, those on the right side s ...

Combining AngularJS, D3, and JQuery on a single webpage can pose challenges, specifically with D3's ability to accurately read DOM dimensions

I am encountering an issue with my webpage not loading properly. I have structured it using a simple header-body-footer layout in html5 and CSS3. +----------+ | HEADER | +---+----------+---+ | BODY | +---+----------+---+ | FOOTE ...

What is causing the ng-show function to malfunction after building with phonegap?

My current javascript framework for my PhoneGap app is the Ionic Framework. I have a specific item on one of my pages that I want to make expandable and collapsible by clicking an anchor on the page. Here is what the code looks like: In the HTML file: & ...

Is there a way to simulate a click event within a Jasmine unit test specifically for an Angular Directive?

During the implementation of my directive's link function: $document.on('click.sortColumnList', function () { viewToggleController.closeSortColumnList(); scope.$apply(); }); While creating my unit test using Jasmine: describe(&apo ...

Setting the texture for a loaded glb model using Three.js

After successfully loading a basic glb model created in SketchUp using Three.JS, I encountered an issue with displaying text on the model. The model includes a group identified as Text. Despite being able to load and visualize the model correctly in Three ...

The query callback does not recognize 'done' as a function, leading to a

I'm attempting to save the result of a query into a variable. I've learned that using a callback is necessary for this task. However, I am encountering errors in the process. function fetchUserData(user) { if (user.checkUserStatus) { var u ...

Leveraging req.files for uploading multiple files at once

When it comes to handling a multiple file upload on the client side, I have encountered an issue with my HTML code. Here is what it looks like: form(method='post', enctype='multipart/form-data')#createReportForm input(type='file ...