The AngularJS Protractor e2e Testing encountered an error: TypeError - The object does not contain the 'input' method

I have an application with two main pages. The first page serves as the landing page and features a login button. When users click on this button, they are redirected to login.html, where they are prompted to enter their username and password.

The code snippet for the process is as follows:

index.html

<a ui-sref="login" class="fa fa-sign-in" href="/login">&nbsp;Login</a>

and

login.html

<input type="text" id="username" name="username" placeholder="Username" ng-model="user.username" required="" autocomplete="off" class="ng-pristine ng-invalid ng-invalid-required">

<input type="password" name="password" placeholder="Password" ng-model="user.password" required="" autocomplete="off" class="ng-pristine ng-invalid ng-invalid-required">

During testing, after successfully clicking the login button and verifying the redirection, I encountered an error when trying to input data into the username and password fields. It seemed as if the input boxes were not being recognized. I attempted to introduce a browser sleep, but it did not resolve the issue.

// in test/e2e/main.spec.js
describe('E2E: main page', function(){

'use strict';

var ptor;


// initialize the protractor instance
beforeEach(function(){
    browser.get('http://127.0.0.1:9000/');
    ptor = protractor.getInstance();
});

it('it should navigate to the login page upon clicking the login button', function(){

    var link = element(by.css('.fa.fa-sign-in'))

    link.click();


    browser.sleep(4000);

    expect(ptor.getCurrentUrl()).toMatch(/\/login/);

    element(by.model('user.username')).sendKeys('test');
    element(by.model('user.password')).sendKeys('test');

});


});

Any suggestions or insights on how to resolve this issue?

UPDATE:

Switching from by.input to by.model resolved the input box recognition issue, even though the initial method should have worked according to the resource I was following. Quite peculiar.

Answer №1

The by.input() method is no longer supported and it is recommended to use by.model() instead. If necessary, you can create your own locator with the following code:

by.addLocator('input', function(model, opt_parentElement) {
  using = using || document;
  var prefixes = ['ng-', 'ng_', 'data-ng-', 'x-ng-', 'ng\\:'];
  for (var p = 0; p < prefixes.length; ++p) {
      var selector = 'input[' + prefixes[p] + 'model="' + model + '"]';
      var inputs = using.querySelectorAll(selector);
      if (inputs.length) {
          return inputs;
      }
   }
});

// Example of using the custom locator
element(by.input('username')).sendKeys('test');

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

The website is missing the display of Google Maps

The Google map is not displaying on my website page that uses PHP. I need assistance with this issue. Below is the webpage URL and the source code: <section class="meteor-google-map fullwidth block" style="height: 450px; border: solid transparent; bo ...

Using importNode in the context of Microsoft Edge involves transferring a

I am facing an issue with a dynamic page that has the ability to change its main div content using a bar button. The pages are mostly static except for one which contains JavaScript (RGraph charts). To make it work, I am currently using the following code ...

What is the best way to transform a synchronous function call into an observable?

Is there a conventional method or developer in RxJS 6 library that can transform a function call into an observable, as shown below? const liftFun = fun => { try { return of(fun()) } catch (err) { return throwError(err) } ...

Implementing Jquery Datatables in C# Codebase

I'm struggling to populate my jQuery Datatable with a List. Currently, I am writing the list to a file and accessing it in my view-model. Is this the correct approach? This is the snippet of my code: List<string> list = new List<string> ...

Having difficulty updating the state within a function

While working on developing a server-side pagination that mimics a static version, I have almost completed it. However, I have run into some issues that I am struggling to resolve. Here's how my code currently looks: const LiveIndex = (props) => { ...

Custom JavaScript code in Bootstrap Navbar Toggler results in closing the menu when a dropdown is clicked

As a newcomer to JavaScript, I am currently learning the language while working on a website. I have customized a template that I found online but am struggling with the JS code that I'm not very familiar with. Here's my issue: When using the na ...

XMLHttp request experiencing mixed content issues

Struggling with obtaining OAuth Tokens from a POST request through the Bungie API using javascript and XMLHttpRequest. Despite both my website and the API endpoint being secure (https), every post request I send returns a Mixed Content page error. I'v ...

Is there a way for me to redirect back to the original path?

Whenever I utilize <Redirect to="<same_path>" />, a warning pops up: Warning: You tried to redirect to the same route you're currently on: "<path>". In one of my Components, I trigger another Component that prompts for either submis ...

Assign individual heights to multiple iFrames according to their content's height

Dealing with multiple iframes on a single page. Each iframe is sourced from my domain. The goal is to automatically calculate and set the height of each iframe on the page. The current code sets all iframe heights to match that of a specific iframe: fun ...

Animate CSS with Javascript in reverse direction

Forgive me if this is a silly question, but I'm having trouble. I need a slide-in navigation menu for smaller screens that is triggered by JavaScript. Here is what I currently have: HTML <nav class="responsive"> <ul class="nav-list unstyl ...

I am encountering an issue with my function where I aim to prevent the creation of a node using duplicate coordinates

Trying to avoid creating a node with existing coordinates, I implemented a check in my code. The check is supposed to determine if there are any nodes with the same coordinates already present. However, it seems that the check is not working as expected an ...

Utilizing additional PHP files to handle the AJAX post request and subsequently execute the PHP script

I have been tasked with a complex assignment that I am struggling to comprehend. Let me provide a brief overview of what is required of me. There are three files involved in this task: 1. An HTML file that sends an AJAX post request to passwrapper.php. 2. ...

Images set as the og:image on the following 14 websites hosted on Vercel require authentication to be displayed

After deploying my Next.js 14 site on Vercel, I placed opengraph-image.png in the app folder alongside layout.tsx. Upon inspecting the meta tag, I noticed the following: <meta property="og:image" content="https://ns-website-6pnvd8ili-mare ...

Converting null to an empty string in Ionic React - A step-by-step guide

Seeking help with submitting a form through an API endpoint. The issue arises with the 'phone' input, which is not a required field and is causing validation errors. Here is the error message received when 'phone' input is left empty: { ...

What is the best way to show a nested object in an API request?

I am facing a challenge in utilizing scriplet tags in express to showcase conversion rates from a foreign exchange rate API using ejs. The JSON response is presented below, and my goal is to exhibit each conversion_rate key-value pair on the results.ejs p ...

Different ways to activate the system bell in Node.js

Currently, I have a custom nodejs script running for an extended period and I'm seeking a way to receive a notification once the script finishes its execution. Is there a method in nodejs that can be used to activate the "System Bell" alert? ...

What could be causing my HTML elements to shift position based on varying screen sizes or zoom levels?

Does anyone else experience their HTML and CSS elements shifting around based on the screen size or zoom level? I have screenshots illustrating this issue. Here is how it currently appears And here is how it's supposed to look ...

Tips for preventing the need to create a function within a loop

Currently, I am in the process of collecting data through REST calls. I have created a function that accesses a "directory" endpoint to retrieve a list of individuals. While I can easily obtain details about their children, I need to make individual AP ...

Having issues with Node.js POST requests not functioning properly

Currently diving into learning the MEAN stack and facing a challenge with executing POST requests on the server. Here is a snippet from my server.js script: var express = require('express'); var bodyParser = require('body-parser'); v ...

Javascript: Troubleshooting Unexpected Variable Behavior in HTML Code

My issue is as follows: I am attempting to retrieve text from a JSON file in my HTML. In the header of my HTML, I have linked a tag with the following code: var language = ""; var langDoc = null; //Function to change the value function setLang() { v ...