【发布时间】:2021-10-22 17:59:43
【问题描述】:
我想在单击按钮之前编辑 href 链接。我想使用常量。我遇到了问题:
Error: Evaluation failed: ReferenceError: dourl2 is not defined
我的代码如下所示:
#1 从按钮获取 href 链接
const dourl = await page.$eval("#dodaj_do_koszyka"+ link, el => el.href);
#2 将“000”添加到链接:
const dourl2 = dourl + '000';
#3 将更改后的 href 放到按钮上:
await page.$eval("#dodaj_do_koszyka" + link, element => element.href = '{dourl2}' );
如何正确地将 const 放在这个地方?此方法产生错误:
'{dourl2}'
谢谢
【问题讨论】:
-
你确定
element.href = '{dourl2}'被引用了吗?'{dourl2}'是一个字符串,它不会导致这个错误。
标签: constants puppeteer href eval evaluate