I am trying to use an XPath and an external variable in Puppeteer's evaluate function, but there is a problem:
- if I use the evaluate function with passing in the external variable then I can't pass in the XPath,
- if I remove the XPath everything is fine, but I need to do it with an XPath.
I just get this error:
UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON --> starting at object with constructor 'BrowserContext' | property '_browser' -> object with constructor 'Browser' --- property '_defaultContext' closes the circle Are you passing a nested JSHandle? at JSON.stringify ()
This is my code (you can ignore the long XPath selector):
let lastNameIn = await page.$x('//*[contains(translate(@placeholder,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ"), "LAST") and contains(translate(@placeholder,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ"), "NAME"))]')
lastname = "test"
await page.evaluate((lastname, lastNameIn) => {
el => el.value = lastname, lastNameIn[0]
}, lastname, lastNameIn)