剧作家如果找到了很多地段,则如何单击特定元素?

发布于 2025-02-09 16:12:01 字数 732 浏览 3 评论 0原文

我很难单击第三个元素。我尝试了索引,并且.thixd()方法仍然不起作用。

测试结果: 测试结果

    async clickAddToCart(page) {
        const element = commonEl.addToCart();
        await page.evaluate((el) => document.querySelector(el)[3].click(), element)
    }

 addToCart() {
        return ('.bg-blue-500.text-white.font-semibold.rounded-md');
    }

试图获得这个元素 试图获得此元素

I having a hard time clicking 3rd element found. I tried index, and .third() method still not working.

Test Result:
Test Result

    async clickAddToCart(page) {
        const element = commonEl.addToCart();
        await page.evaluate((el) => document.querySelector(el)[3].click(), element)
    }

 addToCart() {
        return ('.bg-blue-500.text-white.font-semibold.rounded-md');
    }

Trying to get this element
Trying to get this element

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

手心的温暖 2025-02-16 16:12:01

您可以为此使用nth选择器。对于第三个按钮,您必须使用索引值为2。

await page.locator('button.py-4 >> nth=2').click();

You can use the nth selector for this. For the third button you have to use the index value as 2.

await page.locator('button.py-4 >> nth=2').click();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文