How to implement If condition

Skip to first unread message

Swetha Gorantla

Aug 25, 2021, 7:02:00 AMAug 25
Can someone please help me to resolve this issue?
I have the following code

async function reserved_slot(page, target_url) {
var fifthwkslotdate= new Date();
fifthwkslotdate.setDate(fifthwkslotdate.getDate() + 7);
await page.goto(`${target_url}en-GB/slots/delivery/${fifthwkslotdate}?slotGroup=1`, {waitUntil: 'networkidle2'});
await page.waitForTimeout(3000);
await page.screenshot({path: 'HomeDeliveryFifthwkPage.png'});
await'[class="button button-secondary small available-slot--button available-slot--button--cc-link-enabled"]');
await page.waitForTimeout(3000);
await page.screenshot({ path: 'Reservedelslotpage.png'});

By using this code i am reserving the slot. But if slot is not avialable in the page i have to go to another page to book the slot.
1) await page.goto(`${target_url}en-GB/slots/delivery/${fifthwkslotdate}?slotGroup=1`, {waitUntil: 'networkidle2'}); after going to this page i can come to know whether slot is there or not by seeing this message "Delivery slots for these dates are fully booked". How to capture this value from the above page response.
2) If slot is available i can book the slot using "await'[class="button button-secondary small available-slot--button available-slot--button--cc-link-enabled"]');" other wise i have to go other page by using "fifthwkslotdate.setDate(fifthwkslotdate.getDate() + 0);". How to implement this condition.

Thanks in advance.
Reply all
Reply to author
0 new messages