使用带空格的属性选择器单击 Puppeteer 页面
此 Meteor 代码在服务器上使用 Puppeteer 13.1.2。它使用 for
循环使用其 title 属性打开 a
链接。只要该值不包含空格,它就可以工作,但无法打开包含空格的属性值的弹出页面。知道如何打开这些弹出窗口吗? 谢谢
const headings = ['One', 'Tow', 'Three/Four', 'Five Six', "Seven and more"]
for (let i = 0; i < headings.length; i++) {
console.log('headings: ', headings[i])
const [popup] = await Promise.all([
new Promise((resolve) => page.once('popup', resolve)),
page.click('a[title~="' + headings[i] + '"]'),
]);
}
<tr class="rowDark">
<td width="10%" align="center">
<input type="checkbox" name="selectedCheckboxes" value="Five Six" disabled="disabled" id="FiveSix" />
</td>
<td width="90%" class="smallText" align="left">
<a href="/is/ASD.do?action=create&area=Five Six&iType=e" class="textLink" target="sons" title="Five Six (opens new window)" onclick="return displayReason(this.href);">
Five Six
</a>
</td>
</tr>
使用上面的代码,我收到以下错误:错误:找不到选择器的节点:a[title〜=“五六”]
This Meteor code uses Puppeteer 13.1.2 on the server. It uses a for
loops to open an a
link using its title attribute. It works as long as the value has no spaces but it failes to open the popup page with the attribute values that contains spaces. Any idea how to open these popups?
Thanks
const headings = ['One', 'Tow', 'Three/Four', 'Five Six', "Seven and more"]
for (let i = 0; i < headings.length; i++) {
console.log('headings: ', headings[i])
const [popup] = await Promise.all([
new Promise((resolve) => page.once('popup', resolve)),
page.click('a[title~="' + headings[i] + '"]'),
]);
}
<tr class="rowDark">
<td width="10%" align="center">
<input type="checkbox" name="selectedCheckboxes" value="Five Six" disabled="disabled" id="FiveSix" />
</td>
<td width="90%" class="smallText" align="left">
<a href="/is/ASD.do?action=create&area=Five Six&iType=e" class="textLink" target="sons" title="Five Six (opens new window)" onclick="return displayReason(this.href);">
Five Six
</a>
</td>
</tr>
With above code I got following error: Error: No node found for selector: a[title~="Five Six"]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以首先选择所有
.textLink
元素,然后按其标题值的文本过滤找到的元素。以下是两个用于按属性过滤元素的辅助函数:在您的特定示例中,这现在应该可以工作:
You could first select all
.textLink
elements and then filter the found elements by its title value's text. Here are 2 helper functions for filtering elements by its properties:On your particular example this should now work: