[SOLVED] how to concatenate a date string inside an html element locator with javascript

Issue

I have the following line of code in a playwright test using js

await page.click('[aria-label="Choose Friday, March 4th, 2022"]');

I want to store the date inside a variable like this:

let date = "Friday, March 4th, 2022";

which I have as

await page.click('[aria-label="Choose 'date' "]');

however in my editor I see the warning

',' expected

Solution

To concatenate a string use +

await page.click('[aria-label="Choose ' + date + ' "]');

Answered By – Jonathan Clark

Answer Checked By – Candace Johnson (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *