How can I select an element with Puppeteer if it has backslash symbols in the selector?
To grab an element on a website to use with puppeteer I usually just directly copy and paste the selector from the browser. However on this new website I'm working with, the following selector does nothing
await page.waitForSelector('#forms\.login\.email')
This is the HTML tag
<input type="email" tabindex="0" class="_a _q _eo _bn _ep _dh _cr _di _cq _cu _eq _es _et" data-test-id="field-email" label="Email Address" autocomplete="email" id="forms.login.email" theme="[object Object]" value="">
use the double backslash:
await page.waitForSelector('#forms\\.login\\.email')
see here:
As the backslash is also an escape character in JavaScript, if you are entering a literal string, you must escape it twice (once for the JavaScript string, and another time for querySelector()):
https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector#escaping_special_characters