简体   繁体   中英

How to make a click on a button that doesnt have id on pupeteer

I'm working on a bot that buy by himself, but after he put the Credit card, exp and cvv, the page has a button that doesn't have id, only have class, the code of the button is

<button type="submit" class="btn btn-primary btn-block submit_silentOrderPostForm checkout-next">Siguiente</button>

I'm trying with

await page.click('#btn btn-primary btn-block submit_silentOrderPostForm checkout-next')

and with

await page.click('btn btn-primary btn-block submit_silentOrderPostForm checkout-next')

but it doesn't work. How may I do it? Thanks

Add a unique class name like mybutton or whatever and add it to that button.

<button type="submit" class="mybutton btn btn-primary btn-block submit_silentOrderPostForm checkout-next">Siguiente</button>

Call it like this:

 await page.click('mybutton')

I hope that gives you an idea.

You can identify the element with a query selector that checks as much info as you have, like this...

var B=document.querySelectorAll('button[type="submit"][class*="submit_silentOrderPostForm"]')[0];


B.style.color='red'; // It works! :)

Page.click requires a CSS selector as its mandatory parameter. Do not forget that CSS class selector syntax is: .class-name , so you will need something like this:

await page.click('.btn.btn-primary.btn-block.submit_silentOrderPostForm.checkout-next')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM