最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Puppeteer - select element with multiple selectors - Stack Overflow

programmeradmin1浏览0评论

I have the following html:

<html>

<body>
    <div title="test" class="test">hello</div>
    <input onclick="" type="confusepuppet" value="google" class="button">
    <form action="">
        <input onclick="" type="submit" value="yahoo" class="button">
    </form>
    <form action="">
        <input onclick="" type="submit" value="google" class="button">
    </form>


</body>

</html>

and suppose I want to click the button to redirect to google, I can't use value="google" or type="submit", I have to use both value="google" AND type="submit" to avoid clicking the wrong button.

How do I acplish this in puppeteer?

This doesn't work:

await page.click('input[value="google",type="submit"]')

I have the following html:

<html>

<body>
    <div title="test" class="test">hello</div>
    <input onclick="" type="confusepuppet" value="google" class="button">
    <form action="http://yahoo.">
        <input onclick="" type="submit" value="yahoo" class="button">
    </form>
    <form action="http://google.">
        <input onclick="" type="submit" value="google" class="button">
    </form>


</body>

</html>

and suppose I want to click the button to redirect to google., I can't use value="google" or type="submit", I have to use both value="google" AND type="submit" to avoid clicking the wrong button.

How do I acplish this in puppeteer?

This doesn't work:

await page.click('input[value="google",type="submit"]')

Share Improve this question asked Feb 8, 2020 at 1:54 medsmeds 23k42 gold badges175 silver badges337 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Multiple value selector:

await page.click('input[value="google"][type="submit"]');

You can use attribute selector

const element = await page.$('[value="google"]');
await element.click();
发布评论

评论列表(0)

  1. 暂无评论