What are the steps to configure the datepicker with webdriverIO?

I am working on automating the booking.com page and I have successfully automated the process to open the calendar. However, I am now facing the challenge of selecting check-in and check-out dates. Can someone guide me on how to achieve this?

Below is an excerpt of my code:

    And user selects dates from "2020-06-16" to "2020-06-26"

BookingStep

When('user selects dates from {string} to {string}',()=>{
BookingPage.checkInOut.click();
browser.debug();  });

Booking page

class BookingPage{
get whereAreYouGoingTextBox(){return $('#ss')};
get checkInOut(){return $('div.xp__dates-inner')};  }export default new BookingPage();

Answer №1

If you are struggling to interact with the date field and the cancel link on a date picker object, I've found a solution that may work for you.

After facing this issue myself, I discovered that the randomly generated XPATH/CSS Selector for the datepicker object was causing tests to fail. To overcome this, I identified a unique css ID above the datepicker element and used it as a reference point. I then traced the HTML path from that ID to the datepicker input tag and appended it to effectively set a value in the date picker text field.

Now, to close the datepicker object, you can use JavaScript. Simply inspect the 'Cancel' link element, copy the CSS Selector ID (e.g., #cancelLink), and run the code snippet below:

browser.execute(() => document.querySelector('#cancelLink').click());

With these steps, you should be able to handle the date picker field and the cancel link successfully. Feel free to use the code snippet below as a reference:

class DataSearchSortAndDateRangePage {
    get startDate() { 
        return $('//*[@id="filtersSideBar"]/div[2]/div/div[2]/div[1]/div/input'); 
    }

    setStartDate(date) {
        this.startDate.waitForClickable({ timeout: browser.config.timeOutValue });
        this.startDate.setValue(date);
        browser.execute(() => document.querySelector('body > div.md-datepicker-dialog.md-theme-default > div.md-datepicker-body > div.md-dialog-actions.md-datepicker-body-footer > button > div > div').click());
    }
}

export default new DataSearchSortAndDateRangePage();

I hope this explanation and code snippet prove helpful to 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

Tips for representing entire months as object keys using numerical values

Currently, I find myself a bit puzzled as to why my code is not functioning as expected, and I am hopeful that you all could assist me in solving this issue. The data structure I am working with consists of years and corresponding months. chosenMonths = { ...

Is there a way to prevent a form from automatically submitting once all inputs have been completed? (Using react-hook-form)

After creating a multi-step-form using shadcn, next, zod, and react-hook-form, I encountered an issue where the form is being submitted on step 3 instead of when clicking the submit button. form.tsx const form = useForm<Inputs>({ resolve ...

What is the best way to incorporate JavaScript multiple times on a single webpage?

<script type="text/javascript"> $(function() { var newYear = document.getElementById('HF'); alert('hehe' + newYear); $('#countdown1').countdown({ until: newYear, format: ' ...

What could be the reason for my SQL query functioning correctly in my editor, but not in my JavaScript function?

When I run my SQL statement in my SQL editor, it works perfectly fine. However, when I try to use it in my JavaScript function, I get an error saying there is an invalid column for my client ID. function getFeedposts(data) { var limit = data.dollarLimit; ...

A problem has occurred in Next.js where FileReader is not recognized and is causing a Reference

Exploring the latest features of Next.js 13 with the /app directory, I encountered an issue while using the FileReader in a basic client-side component that manages an input form. Here is a brief overview of the code: "use client"; import React, ...

transforming an array of undefined values into an array of strings

I am attempting to transfer an array value from the frontend to the backend, but I am encountering errors during the process. Below is the response data: { sender: 'venkat', numbers: '[919361667266, 919361667266, 919361667266, 919361667 ...

Curious as to why body.scrollTop functions differently in Google Chrome and Firefox compared to Microsoft Edge

Up until recently, the code body.scrollTop was functioning correctly in my Chrome browser. However, I've noticed that now it is returning 0 in both Firefox and Chrome, but still giving the proper value in Microsoft Edge. Is there anyone who can assis ...

Can Selenium be utilized to interact with a button in a Google Slides Presentation?

Within Google Slides, there is a feature located under tools >> Linked Objects known as "Update all": https://i.stack.imgur.com/mbXoG.png This function updates all elements in the Presentation. Although Google App Scripts can achieve something simi ...

I'm having trouble figuring out the code for the path in the POST request for my basic login form application

I have built a basic login form application in node.js. Although I can successfully display the login form and input login data, my POST request to capture the login data is not functioning correctly. I am encountering a POST http://localhost:3000/client 4 ...

When the component is initialized, the computed property is not being evaluated

My maps component initializes a Google map, adds markers based on props passed from the parent, and sets the correct bounds of the map. However, the markers are added through a computed property to make it reactive. Everything seems to be working fine, exc ...

What is the best way to transform an array of lists into a neatly organized state?

I recently received a list of breweries from an API call and I am trying to format it into my React state container. Here is what I have so far: state = { breweries: [ {name: Foo, long: 45, lat: -39.239}, ...

Rendering user actions instantly in React.js without waiting for server propagation

I am currently developing a shopping list web application where users can toggle items as 'checked' or 'unchecked'. The flow of data in this application is as follows: click on item checkbox --> send database update request --> ...

AngularJS implemented to trigger a popup alert after a certain duration of time has elapsed since the

Can we create a popup alert that says "Error Contacting Server" when the http request does not receive any response? .controller('items_ctrl',['$scope','$http',function($scope,$http){ $scope.shop_id=localStorage.getItem(" ...

Guide to passing the parent state as a prop to a child component and enabling the child to modify the state

I have a situation where my parent component holds 4 buttons to set a payment state, and I need to pass this state to a text field child component. Additionally, I want the text field to be editable so that the state can also be modified through it. My att ...

Tips for waiting for a page to reload using Selenium Webdriver version 2.47.1

Currently, I am utilizing WebDriver (Java) to conduct a special test in which a page refreshes itself upon logging on. I have encountered difficulties waiting for the element to load as it is already present before the reload occurs. At this point, my on ...

Is it possible to utilize Jsoup to extract specific portions of JavaScript code from a webpage?

I am looking to extract data from the following script: $(document).ready(function(){ $("#areaName").val(1);$("#state").val(29);$("#city").val(1); $("#subareaName").val(1);$("#lane").val(1); } Specifically, I need to retrieve values such as areaName ...

Struggling to meet PWA lighthouse test requirements even with service worker correctly installed

Recently, I've been diving into PWA development and I've encountered a roadblock. Despite successfully setting up my service worker and caching files, my app is not receiving the PWA mark for being installable when tested with Lighthouse. I' ...

What is the best way to iterate through files within a directory and its nested subdirectories using electron?

I am currently working on developing a desktop application that involves scanning through a directory, including all subdirectories, to locate files containing specific characters in their filenames. Is it feasible to accomplish this task using Electron? ...

Preventing duplication of code execution in recycled PHP elements

Currently, I have implemented a generic toolbar that is used on multiple pages of my web application by using PHP include. This toolbar contains log in/log out functionality and checks the log in status upon loading to update its UI accordingly. Initially ...

Can you explain the significance of the '#' symbol within the input tag?

I was reading an article about Angular 2 and came across a code snippet that uses <input type='text' #hobby>. This "#" symbol is being used to extract the value typed into the textbox without using ngModal. I am confused about what exactly ...