Choosing a date in a Datepicker with selenium: A step-by-step guide

Can someone help me figure out how to select elements for the start date and end date in a datepicker? I've tried the following:

driver.findElement(By.cssSelector("span.add-on > i.enticon-calendar")).click();    driver.findElement(By.xpath("//div[@id='sizcache0696532219872199']/div/table/tbody/tr[5]/td[7]")).click();

However, I couldn't locate the second element with sizcache0696532219872199.

Any advice on how to select the End Date and Start Date properly would be much appreciated. Thank you!

Here is the HTML code:

<div class="control-group">

    <label class="control-label">

        StartDate

    </label>
    <div class="controls">
        <div class="input-append date datepicker-start" data-date-format="yyyy-mm-dd">
            <input class="span2 start-date" type="text" value="" placeholder="YYYY-MM-DD" size="16" name="start"></input>
            <span class="add-on">
                <i class="enticon-calendar"></i>
            </span>
        </div>
    </div>

</div>
<div class="control-group">

    <label class="control-label">

        EndDate

    </label>
    <div class="controls">
        <div class="input-append date datepicker-end" data-date-format="yyyy-mm-dd" data-date="">
            <input class="span2 end-date" type="text" value="" placeholder="YYYY-MM-DD" size="16" name="end"></input>
            <span class="add-on">
                <i class="enticon-calendar"></i>
            </span>
        </div>
    </div>

</div>

Answer №1

Consider using the following selector options:

// Click on the calendar icon within the start date picker
driver.findElement(By.Css(".datepicker-start .enticon-calendar")).Click();

// Repeat the process for the end date
driver.findElement(By.Css(".datepicker-end .enticon-calendar")).Click();

I trust these suggestions will be beneficial. Thank you.

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

Parse a string in the format of "1-10" to extract the numbers and generate an array containing the sequence of numbers within the range

Looking to convert a string in the format "1-10" into an array containing the numbers within that range. Display the array on the screen using a for loop. For example, if "1-5" is provided, the resulting array should be: {1, 2, 3, 4, 5} Create a workflow ...

accordion menu: stuck in my list like a trapped diver due to the overflow

I need assistance with creating a side menu. Here is the current code I have: function opensubmenus() { $('#submenus').css("display", "block"); } #menus { overflow-y: scroll; width: 150px; background-color: blue; } #submenus { backgr ...

Holding off on completing a task until the outcomes of two parallel API requests are received

Upon page load, I have two asynchronous API calls that need to be completed before I can calculate the percentage change of their returned values. To ensure both APIs have been called successfully and the total variables are populated, I am currently using ...

Enhance jQuery for a dynamic navigation dropdown with multiple sub-menus

Looking for help with a jQuery script as I am a beginner in using jQuery. jQuery(document).ready(function ($) { $(".sub-menu").hide(); $(".current_page_item .sub-menu").slideDown(200);; $("li.menu-item").click(function () { if ($('.sub-menu&apos ...

Prevent a hyperlink from being accessible until a timer has finished counting down using J

I have a link with the following HTML: <a class="modal-button" id="submitLink" > When clicked, a jQuery function is triggered which sends an ajax request to my server. I have implemented a countdown timer that displays if the ajax call fails, and ...

Having trouble retrieving information from the Redux store and displaying it in the user interface component

I'm currently diving into the world of Redux and working on a tracker app, but I've hit a roadblock that's had me stuck for days. Your help would be greatly appreciated. Thank you. store.js import { createStore, applyMiddleware, compose } f ...

What is the best way to handle errors generated by my jsdom.jqueryify callback function?

When running this code in node.js, the output is a stack trace of an error that occurs on line 9. Surprisingly, the error on line 7 seems to be 'absorbed' by Node. Even when wrapped in a try/catch statement, the detailed stack trace output is not ...

evolving konami sequence

I am working on creating a .js file for a website that will trigger the embedding of a video when the konami code is entered: Up, Up, Down, Down, Left, Right, Left, Right, B, A, Start (enter). While entering the correct keys, the webpage should display a m ...

Interactive form created with asp.net and dynamic javascript functionality

Hello, I am a beginner in web development. I have created an application that includes a button. When the button is clicked, a popup window should appear with 2 fields and another button. Once the user clicks the button in the popup window, the data ente ...

Unable to retrieve hours from MongoDB date array

Whenever I fetch data from my NodeJS+MongoDB webservice, I am able to retrieve the date format successfully. However, I am facing an issue when trying to extract hours from it. Here is how the date looks in MongoDB: https://i.stack.imgur.com/qxWGL.png I ...

Open a webpage and execute JavaScript with just one click of a bookmark

I found a convenient bookmark that opens my Google Calendar page at http://www.google.com/calendar/renderOnline. Additionally, I have another bookmarklet that applies specific JavaScript to the page: javascript:document.getElementById('gadgetcell&apo ...

The absence of shadows being cast and received is causing issues with the scene's rendering

I've been diving into threejs through game development. I successfully rendered all models in the scene and added some lights, which turned out perfectly fine. However, when trying to cast and receive shadows on the plane, the object shadows in the sc ...

The process of importing mongoose models is not functioning properly

Initially, I had no issues when defining my schema and models in the same file where they were being used. However, when I tried to import them following the examples I found online like this... index.js var mongoose = require('mongoose'); var ...

Guide on accessing nested objects in EJS templates

I'm attempting to extract the "info" portion from the JSON data provided below. In my code snippet, I'm using the <%= person['person_details']%> to access that specific section of the JSON. However, it only returns [Object Obje ...

How can I specifically disable the next month in MUI Datepicker?

Employing MUI version 5, how can I disable only the next month in the datepicker while keeping the others functional? ...

What is the best way to retrieve the value from a textfield in one module and use it in a

How can I access the value of a textField in another module within React.js without importing the entire textfield component? What is the most effective approach to get access to the value variable in a different module? Below is a sample functional textF ...

Error: The value property is undefined and cannot be read at the HTMLButtonElement

I'm currently working on a project where I need to display a dropdown menu of buttons using Pug in order to render an HTML page. To achieve this, I am using the getElementsByClassName('dropdown-item') method to retrieve all the buttons in an ...

displaying a progress bar with percentage using jQuery mobile

Currently, I am in the process of creating a mobile app with jquery mobile and integrating it with a web service. My goal is to incorporate a progress bar that shows the completion percentage. ...

Embedding links in v-bind:href

I inserted a dynamic link inside the <header></header> section using the method mentioned here: Vue JS and appending a variable to end of a URL Below are the relevant codes: <tr class="notice-row" v-for="(myCase, id) in case ...

Notification for radio button selected

Looking to trigger an alert message when a radio button is not selected? Check out the code below: <form method=post name="spendform" id="spendform"> <input name="price" type="radio" class="invest-coin-check" id="pricemethod" > <button typ ...