Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 + ' "]');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading