I wonder how I can access an element by ID. I want to submit a form.
await page.click("id= 'next'");
--> not possibleawait page.getByRole('button', { id: 'next' }).click();
--> does not compileawait page.getByRole('button', { name: 'Sign in' }).click();
--> work but is language dependentSelecting elements by their ID seems the most robust to me. Am I missing something?
What you are missing in the first example are the square brackets, instead of:
await page.click("id= 'next'");
you should do this:
await page.click("[id='next']");
alternatively, you can use the shorthand version like mentioned in the other answer