Commitments are always left unfulfilled

The code provided above seems to be experiencing issues as "post4" and "post3" are not showing up in the console log. The promise is returned, however, attempting to chain from that promise does not seem to work.

loginPage.prototype.doLogin = function(isGood){
    var d = webdriver.promise.defer();
    this.driver.findElement(webdriver.By.css('input.loginbutton')).click(function() {
        if(isGood){
            //return new statementPage;
            console.log("post3")
            d.fulfill(new statement.statementPage(this.driver));
        } else {
            console.log("post4")
            d.fulfill(this);
        }
    });
    console.log("post5")
    return d.promise;
}

If I try to execute

login.doLogin(true).then(function(){console.log("foo")})
, it won't display post3, post4, or foo in the log.

Even though other promises are working correctly elsewhere in my code, this specific piece of code doesn't seem to be functioning properly.

Answer №1

The click method in webdriverjs does not require any parameters or callbacks, which means that your function was never executed. The source code for the click function can be found in the official API documentation:

webdriver.WebElement.prototype.click = function() {
  return this.schedule_(
      new webdriver.Command(webdriver.CommandName.CLICK_ELEMENT),
      'WebElement.click()');
};

You can see a demonstration of this behavior in action by visiting this JSFiddle link, where a JavaScript function without parameters behaves as expected if the arguments variable is used.

To ensure that your code runs after the click operation is completed, you can use the

element.click().then(function(){d.fulfill()});
syntax to handle promises effectively. For more information on promises in webdriverjs, refer to the official Webdriverjs Promises documentation.

Answer №2

Instead of relying on a callback like this:

element.click(function(){d.fulfill(););

It is recommended to utilize the promise returned by the click event, like so:

element.click().then(function(){d.fulfill()});

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 get Axios to display CSS on the page?

While working on a Web Viewer project with axios for web scraping practice, I encountered an issue where the CSS wasn't loading properly. Here is the code snippet I used: console.log("Tribble-Webviewer is starting!") const express = requir ...

What is the best way to output a received HTML page from the server?

I'm currently working on printing an HTML page that was generated using Node.js on my server. After sending the page to the client side as a response to an AJAX request, I have stored it in a JavaScript variable. var resp_json = printRequest.getRespo ...

Is it advisable and what is the proper way to shift to a different route within a promise's

Trying to utilize Ember controller to make an API call for user creation and then transitionToRoute upon success. Here is the current setup: import ajax from "ic-ajax"; import Ember from "ember"; export default Ember.Controller.extend({ actions: { ...

Can anyone advise on accessing a nested array that contains product objects in JavaScript?

Greetings to all my fellow tech enthusiasts! I've encountered a new challenge involving accessing arrays within an array. This inner array contains two objects - product and quantity. I'm seeking guidance on how to access this nested array. If yo ...

selenium script for extracting information from excel document

I am currently working on a Selenium script that extracts data from an Excel file and then enters that data into a website's text box. The code is successfully fetching and storing the data in an object array, but I'm encountering an error when t ...

How can the lack of div "n" be detected within container "x" using JavaScript?

Is there a way to create an IF statement that checks if a certain div is within a parent container? <div class="parent" id="x">need to check if div id "n" is here....</div> For example, if the parent container ("x") does not contain the div " ...

Mapping an array of objects to an array of Q promises: A step-by-step guide

I am struggling to comprehend this issue. I have a list of positions that I need to convert into an array of promises and then collect them. However, the problem is that positionPromises ends up as an array of nulls ([ null, null ]) var positionPromises ...

Obtaining Header or Footer information from an XLSX file using Angular

CLICK HERE FOR XLSX HEADER IMAGE I am struggling to retrieve the header and footer data from an xlsx file. I have only managed to access the information inside the workbook so far. I attempted to extract the header/footer using the following method, but ...

The dynamic list of iframes is being loaded and encountered an error stating "Safe ResourceURL is required"

Having difficulty loading dynamic list of URLs that contain iframe videos from YouTube. This is the HTML code: <div fxLayout="column"> <div *ngFor="let v of videos"> <div fxLayout="row"> <div> Type: {{v.type}} ...

A single pledge fulfilled in two distinct ways

My code ended up with a promise that raised some questions. Is it acceptable to resolve one condition with the token string value (resolve(token)), while resolving another condition with a promise of type Promise<string>: resolve(resultPromise); con ...

An unexpected error occurred when attempting to launch Chrome while running a .side file through the command line with selenium-side-runner: WebDriverError

Recently, I utilized Selenium in my Chrome browser to record a set of steps that worked flawlessly within the browser. Now, I am eager to automate this process on a daily basis and I was considering running it from the command line to schedule it with cron ...

Include a dynamic key in the setState function in React

In my current state, I have different dropdown options: this.state = { dropdown1: false, dropdown2: false, dropdown3: false } I am looking to access and update these dropdowns using this.setState, where the number after 'dropdown' is dy ...

Javascript adds a comma after every postback event

This particular JavaScript code I am incorporating helps in expanding and collapsing nested grid views. <script type="text/javascript"> $("[src*=plus]").live("click", function () { $(this).closest("tr").after("<tr><td></td ...

Check the validity of multiple selection groups using JavaScript

Here is the link to my JS Fiddle: http://jsfiddle.net/m4tyC/ I am working with multiple select tags and need to validate them upon submission. For example, at least one of size1, color1, or Qty1 must be selected in the first group. If one item is selected ...

Sharing data between services in Angular 2In Angular 2, learn

I currently have a setup consisting of two components linked to 2 services. The first one being a ProductComponent: @Component({ selector: 'app-product', templateUrl: './product.component.html', styleUrls: ['./product.compon ...

The background and border colors of the div are not displaying

Check out this link for the code snippet I'm experiencing an issue where the styles applied to the 'main-content' div are not being displayed. What could be causing this? Interestingly, the styles work perfectly fine on my personal website ...

Using ES6 imports, create a wrapper function for a React higher order component that does not require a variable name

With the commonjs require method, I am able to achieve this: let wrapper = require('./wrapper') let Nephi = wrapper(require('./Nephi')) However, when using es6 import syntax, it appears that I need to do the following: import wrapper ...

Rotation of objects using Three.js on a spherical surface

I have successfully implemented a particle system to evenly distribute points on a sphere and then place instances of a given geometry on those points. Now, I am looking to rotate those geometries to match the surface angle of the sphere. Below is the cur ...

The jQuery change event does not fire once the DIV has been rendered, while working with CakePHP

Whenever a room_id is chosen from the drop-down menu, I utilize the JS helper to automatically fill in the security_deposit and room_rate input fields. However, there seems to be an issue where selecting a room_id causes the room_rate_update jQuery change ...

Modify the text color of the fixed navigation when hovering over specific divs

Sorry if this question has already been asked. I've searched online but haven't come across a satisfactory solution. On my website, I have different background colors - blue and white. The text color in my navigation is mostly white, but I want i ...