Protractor button click not leading to the loading of the next page

After writing the code to click a button on the first page and redirect to the next page, I encountered an issue where the second page took too long to load causing the test to fail.

describe('Login', function() {


it('should display Login home', function() {
browser.get('https://xxxxx.org/yyyy/');
browser.driver.manage().window().maximize();
var acrIdBtn  = browser.driver.findElement(by.css('a.btn.btn-lg.btn-success'));

acrIdBtn.click().then(function() {
    browser.driver.findElement(by.id('ContentPlaceHolder1_MFALoginControl1_UserIDView_txtUserid_UiInput')).click();

  });
});
});

HTML code:

<div class="col-sm-12">
<!-- ngIf: method.label.text !== ' *' && method.input.id.length > 0 --><input tabindex="0" class="form-control ng-pristine ng-scope ng-empty ng-invalid ng-invalid-required ng-touched" id="ContentPlaceHolder1_MFALoginControl1_UserIDView_txtUserid_UiInput" aria-invalid="true" required="" type="text" placeholder="Username" autocomplete="off" ng-if="method.label.text !== ' *' &amp;&amp; method.input.id.length > 0" ng-init="AuthMethod.getUser()" focus-if="" ng-disabled="false" ng-change="AuthMethod.getMethodOnChange(method.input.id)" ng-model="AuthMethod.user"><!-- end ngIf: method.label.text !== ' *' && method.input.id.length > 0 -->
<!-- ngIf: AuthMethod.forgotUser.link --><a class="help-block link--color ng-binding ng-scope" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$MFALoginControl1$UserIDView$ctl00$ContentPlaceHolder1_MFALoginControl1_UserIDView_hlinkUsernameLink','')" ng-if="AuthMethod.forgotUser.link">Forgot User ID</a><!-- end ngIf: AuthMethod.forgotUser.link -->

Answer №1

Let's start by dissecting the code and understanding why this issue is occurring.

describe('Login', function() {
  it('should show Login homepage', function() {
    browser.get('https://xxxxx.org/yyyy/');
    browser.driver.manage().window().maximize();
    var acrIdBtn  = browser.driver.findElement(by.css('a.btn.btn-lg.btn-success'));

    // The click action is thenable, which is fine
    acrIdBtn.click().then(function() {
       // This promise is queued, however, since it's a void function, in JasmineWD,
       // the element finding and clicking functions are void, and the promise
       // is not awaited.
       browser.driver.findElement(by.id('ContentPlaceHolder1_MFALoginControl1_UserIDView_txtUserid_UiInput')).click();
    });
  });
});

A Quick Solution:

To quickly fix this, ensure that the callback returns the promise:

    acrIdBtn.click().then(function() {
       // By returning the click action, JasmineWD will await this callback.
       return browser.driver.findElement(by.id('ContentPlaceHolder1_MFALoginControl1_UserIDView_txtUserid_UiInput')).click();

Moving Away from Control Flow

This still seems to rely on the control flow. As an alternative suggestion, consider moving away from the control flow by setting SELENIUM_PROMISE_MANAGER: false, in your configuration file and using async/await. See Protractor in STS IDE -> Could not find update-config.json for a helpful example of the configuration file and async/await usage.

describe('Login', () => {
  it('should display Login home', async () => {
    await browser.get('https://xxxxx.org/yyyy/');
    await browser.driver.manage().window().maximize();
    const acrIdBtn = element(by.css('a.btn.btn-lg.btn-success'));
    await acrIdBtn.click();
    const contentBtn = element(by.id('ContentPlaceHolder1_MFALoginControl1_UserIDView_txtUserid_UiInput'));
    await contentBtn.click();
  });
});

Answer №2

Before proceeding, it's essential to verify that the button can be clicked:

let loginButton = element(by.id('ContentPlaceHolder1_MFALoginControl1_UserIDView_txtUserid_UiInput'));
await browser.wait(ExpectedConditions.elementToBeClickable(loginButton));
await loginButton.click();

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

AngularJS promise fails to resolve when attempting to read a file using the FileReader

Can someone assist me with a function I am trying to create in my service? I want the function to use FileReader to read a small image file and return the result in a promise to my controller. The issue is that while the file reaches the service without an ...

The phenomena of endless looping between Hibernate and Thymeleaf

I am facing an issue with two classes that have a OneToMany/ManyToOne relation mapped with one attribute. The problem arises when I try to select and pass the object to the view, as I want to parse it to JavaScript using Thymeleaf. However, this causes an ...

Display only one div panel, not both

When I click on div.accordion, I want only the child div.panel to show, not all panel elements. However, with my current code, both div.panel elements are displayed. This is my code. I have a Javascript solution that toggles between setting display: none ...

Issues encountered while manipulating an array in a Vue prop with Filter, forEach, and Push methods

I am attempting a relatively simple task. The parent component passes an ID as a prop to the child component, which then tries to filter the "topics" array to only return the topic with the same ID. However, filtering this array is proving futile. Even us ...

Is it possible to enable caching for CSS and JavaScript files while browsing?

I'm curious to know if browser caching of CSS and JavaScript is done automatically with PHP or if we need to manually implement it through code. What are the benefits of manually caching CSS and JS files to the client's browser using code? Any ...

Does anyone know if it's feasible to return a value from PHP to an HTML form without relying on JavaScript?

Currently, I am in the process of learning how to create a basic web form. My goal is to develop an HTML web form that sends a number to PHP and then displays the number in another text field without refreshing the page. After doing some research online, ...

Extracting information from JSON and presenting it in a structured table format

I've hit a wall with this JavaScript issue on my website. I'm trying to convert API JSON data into a table, and it's working fine when the data is on separate lines. However, when I introduce nested arrays in the JSON data, everything ends u ...

A guide on utilizing buttons within ion list items to execute actions independently for both the button and the list item

Currently, I have a list item with a button that is displayed based on a certain condition. My issue is that when I click the button, a popup should appear, but instead, it also navigates to the next page in the background. Can someone help me figure out h ...

Retrieving input data when utilizing ng-file-upload

I need help with uploading images and their titles using ng-file-upload in the MEAN stack. I am able to save the image successfully, however, I'm facing difficulty in retrieving the data sent along with it. Controller: module.exports = function ($sc ...

Organize information by time intervals using JavaScript

I am currently facing an issue where I need to dynamically sort data from the server based on different fields. While sorting is working flawlessly for all fields, I am encountering a problem with the time slot field. The challenge lies in sorting the data ...

Developing a fresh entity in the world of three.js

Currently engaged in a project that involves creating 3D objects using Three.js, sourced from databases. The connection is established, but encountering failures when attempting to generate a new object. this.type = 'CustomObject'; let shape = ...

Using Strapi to run basic raw SQL queries with MySQL

Trying to execute this query in my test but struggling with the correct syntax. return strapi.connections.default.raw(` delete from nurses; delete from users_permissions_user;`); }); Since this is not using PostgreSQL and MySQL ...

The node.js util module is not compatible with my Vue project

After creating a vue project using vue cli 3 with the command below: vue create hello-world I want to use the util module of Node.js (this one), but when I try to access it in my Vue.js project, it loads Vue's own module instead. How can I load the ...

JavaScript autostop timer feature

An innovative concept is the solo cookie timer that holds off for one hour before resuming its function upon user interaction. No luck with Google. https://jsfiddle.net/m6vqyeu8/ Your input or assistance in creating your own version is greatly appreciate ...

What is the process for excluding code lines from coverage analysis in vitest?

I currently have my unit tests configured with vitest and am exploring options to exclude certain lines of code from vitest coverage analysis. Is there a feature in vitest that functions similarly to /* istanbul ignore next */? I've searched through ...

"Dilemma: Why won't the AJAX form post load inside the

Apologies for the simple question, but I'm experiencing an issue where nothing happens when the button is pressed. Any assistance would be greatly appreciated. AJAX $(document).on("ready", function(){ //Form action $("#wbForm").on("submit", function( ...

Animating Card depth on hover with Material UI

I am looking to add an animation effect to the Card component when the mouse hovers over it. I'm still fairly new to React and struggling with implementing it. Here is what I've tried so far: <Card linkButton={true} href="/servicios/ ...

Angular.js Form Submission Results in Error 405: POST Method is Not Permitted

Every time I attempt to submit my form, I come across a 405 error. Here is the code snippet from my controller: 'use strict'; angular. module('myApp'). component('zipPopup', { templateUrl: 'zip-popup/zip ...

What is the best way to transfer JSON objects from JavaScript to a C# server?

Can JSON objects be sent from JavaScript to a C# server using a Peer to Peer network? Is there an alternative method for sending data in real-time to a C# server? Below are the functions from my JavaScript code: Peer To Peer Code function establishPeer ...

Is there a way to continuously click on a button 99 times or until the code finishes running?

Need Assistance, Please Assist. I am encountering an issue where I have the same type of skip button with identical name and id properties for all products, but only the xpath changes. Can you provide guidance on how to efficiently click on 99 similar ski ...