如何在 puppeteer 中点击 id 包含冒号的元素?

How click on element with id containing colons in puppeteer?

按钮有这样的 id my:very:beautiful:button

<input id="my:very:beautiful:button" type="image" src="https://xxx/search_off.gif" name="my:very:beautiful:button" onmouseout="imgOff('searchBttn', this)" onmouseover="imgOn('searchBttn', this)" class="btn searchBttn" onclick="doSubmit(this, 'clearBttn')">

在 puppeteer 中我尝试点击这个按钮是:

await page.click('#my\:very\:beautiful\:button');

投掷:

Error: Evaluation failed: DOMException: Failed to execute 'querySelector' on 'Document': '#my:very:beautiful:button' is not a valid selector.

双转义字符:

await page.click('#my\:very\:beautiful\:button');

投掷:

Error: No node found for selector: #my\:very\:beautiful\:button

我认为问题出在冒号上。想知道如何点击它吗?

"double escaping" 有效。冒号应该不是问题。

问题很可能是元素还没有被渲染。要等待元素先被渲染,你可以像这样使用函数page.waitForSelector

const selector = '#my\:very\:beautiful\:button';
await page.waitForSelector(selector);
await page.click(selector);

您可以试试属性选择器:

await page.click('[id="my:very:beautiful:button"]');