Guide to transferring the current date to a text box using Angular JS with Protractor

I need to add a date field that is in text type. The HTML code for it is as follows:

<input class="form-control ng-pristine ng-invalid ng-touched" type="text" id="date" name="date">

Can anyone assist me in automatically sending the current date to this field? I have tried several methods, but when I use Date() to get the current date, the test does not even execute.

Answer №1

I found that this method works perfectly in my case. My testing involved using the Google search page to confirm its functionality. I included a 10-second delay so that I could visually verify that it was functioning correctly.

it('should perform a certain action', () => {
    var currentTime = new Date().toString();

    browser.waitForAngularEnabled(false);
    browser.get('http://google.com');
    const searchBox = browser.element(by.id('lst-ib'));

    searchBox.sendKeys(currentTime);

    //expect(something).toBe(true);
});

Answer №2

Getting close! Currently utilizing

this.dateField.sendKeys(d.getMonth() + '/' + d.getDate() + '/' + d.getFullYear());

Resulting in a date of 11/11/2017. This indicates that everything is functioning except for the month. The expected format is MM/DD/YYYY.

Answer №3

Implement momentjs library

import * as moment from 'moment';
const currentDate = moment().format("MMM Do YY");

For additional details, visit here

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

How can I modify the background color of the hamburger menu?

I attempted to modify the background color of the hamburger icon from black to yellow, but unfortunately, I couldn't achieve it. Here's what I tried: //hamburger $(".hamburger").toggleClass("is-active"); var $hamburger = $(".hamburger"); ...

Activate the parent navigation link when on sub-pages

I want to ensure that the parent navigation item is highlighted when a user is on a child page based on the URL. For example, if the user is currently viewing foo1-child and the parent is foo1, I need to apply the active class to Foo 1: http://foo.com/foo ...

Looping through JSON data in jQuery outputs the value 9 when paired with the text() method

I have retrieved JSON data that is structured as follows: { "solution": { "1": { "cell-1": "1", "cell-2": "2", "cell-3": "3", "cell-4": "4", "cell-5": "5", "cell-6": "6", ...

Broadcasting real-time video from a webcam on an HTML website that is accessible locally through a Raspberry Pi device

My goal is to stream live video from a USB camera connected to my Raspberry Pi device onto a simple HTML site that is only visible on localhost. The site will be hosted on the Raspberry Pi itself and will only need to display the video streamed by the Ra ...

Passing along a request using Node.js

I am facing an issue in my project where I need to redirect requests received by a nodejs endpoint to a .NET 7 web API endpoint. The nodejs endpoint is triggered by an external party and it receives the request as expected. However, there seems to be a pro ...

Maintain the original order of rows in the table while shuffling the columns they appear in randomly

I need help with my table setup. The left column contains words in English, while the right column has the same words translated into Korean. Is there a way to keep the rows intact while randomizing the order of the columns? Here's an example: <ta ...

The previous and next arrows do not have a looping feature

I have a collection of 10 HTML pages stored in a folder called PROJECTS. Everything is functioning properly, except for the prev and next arrow navigation buttons. The issue arises when navigating to the last page (e.g., projectPage_10.html) from my Projec ...

Can images and models be imported into three.js from a byte array?

Is it feasible to load images and models directly from byte arrays in three.js? For instance, downloading a compressed file, extracting it in JavaScript, and feeding the byte array into the loaders? Thank you ...

The URL cannot be loaded by the XMLHttpRequest due to an invalid HTTP status code 400, which occurred when using a WebApi with AngularJS

I have encountered an issue with my WebApi Application and a basic web client that consumes it. I use angularJS to send requests from the web client to the WebApi, and CORS is enabled. While I was able to resolve a problem with POST requests in Chrome by ...

Exploring alternative methods of iterating over the values in a key-value pair within an AngularJS framework

My key-value pair consists of a long list of file names stored in the variable $ctrl.displayData- 143:"/this/is/a/very/long/fil22↵/this/is/a/very/long/file/path.php↵anotherone.php↵newfilel123.php" When I use ng-repeat to display these file names, t ...

In a JavaScript array of objects, the Vuetify select :items feature allows you to assign an id and name to each object. When a name is selected, the corresponding id is automatically

I am currently working with an array of objects that contain both an id and a name property: Teams [ { id: 1, name: 'team1' }, { id:2, name: 'team2' } ] Is there a way to dynamically pass the names as items in a vuetify selec ...

Firefox browser fails to follow ng-href links

When using ng-href, I noticed that it works correctly on Chrome but not on Firefox. On the page www.mydomian.com/clubs/ in my Rails app, I have the following Haml code: %a{'ng-href' => '\players\{{player.id}}'} {{player.n ...

DOMException: Access to property "apply" on a cross-origin object has been denied

Over the last day, I've been tackling the FreeCodeCamp assignment "quote machine". Everything is working fine except for the tweet button. You can tweet as many times as you like for one single quote, but not for multiple quotes (once you tweet one, y ...

Refresh the Angular ion-view from a different controller

Greetings to all fellow developers on stackoverflow! I am a newbie here and just starting out with AngularJS. My current project involves building an Ionic app, but I am encountering an issue that I need assistance with. The goal is to update the date di ...

Unable to establish a connection with the default port on Mongo DB while utilizing Node.js

I am new to using Node.js and I'm trying to establish a connection with MongoDB in my Node.js application, but I'm encountering issues. Here is the code snippet: var mongo = require("mongodb"); var host="127.0.0.1"; var port=mongo.Connection.DE ...

Missing ghost image appears when you drag and drop the file

New to JavaScript... As a rookie in coding, I often get interesting requests from my partner who is a kindergarten teacher. Recently, she asked me to create a "Function Machine" for her classroom activities. With some trial and error, I managed to put tog ...

Efficiently removing a duplicated component in Vue: A step-by-step guide

I am trying to find a way to target and remove a component that I duplicated using the v-for directive in my multiple stopwatch application. Currently, I can only delete the last duplicated component, but I want the ability to remove any targeted component ...

Prisma encountered an error with the database string: Invalid MongoDB connection string

I'm encountering an issue with my MongoDB data provider, as I am informed that my connection string is invalid. The specific error message states: The provided database string is invalid. MongoDB connection string error: Missing delimiting slash betw ...

Failure to process JsonWebTokenError due to a corrupted signature in the middleware

I am facing an issue with my middleware when the jwt.verify(request.token, process.env.SECRET) function raises a JsonWebTokenError: invalid signature with middleware error upon receiving an invalid token. Despite configuring my middleware correctly, this e ...

JavaScript is always overlooked and goes unused

Can you figure out why the Javascript code isn't working? <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <script type="text/javascript"> function ChangeDisplay() { alert("Changing"); document ...