NeweggBot
NeweggBot copied to clipboard
Issue with bot continuously adding item to cart without checking out?
Hi, I changed the code per https://github.com/Ataraksia/NeweggBot/pull/35, but must have screwed up somewhere. The bot keeps adding items to the cart, but does not find the secure checkout button. This is the code I currently have.
async function check_cart (page) { const amountElementName = ".summary-content-total"
await page.waitForTimeout(250)
try {
await page.waitForSelector('span.amount', { timeout: 1000 })
var amountElement = await page.$('span.amount')
var text = await page.evaluate(element => element.textContent, element)
await page.waitForSelector('button.close' , { timeout: 6000 })
var maskCloseButton = await page.$$('button.close')
if (maskCloseButton.length > 0) {
await maskCloseButton[0].click()
}
await page.waitForSelector(amountElementName, { timeout: 1000 })
var amountElement = await page.$(amountElementName)
var text = await page.evaluate(element => element.textContent, amountElement)
// Check that the Cart total is not zero - indicating that the cart has items
if (parseInt(text.split('$')[1]) === 0) {
throw new Error("There are no items in the cart")
}
if (parseInt(text.split('$')[1]) > config.price_limit) {
await report("Price exceeds limit, removing from cart")
var button = await page.$$('button.btn.btn-mini');
while (true) {
try {
await button[1].click()
} catch (err) {
break
}
}
return false
}
await report("Card added to cart, attempting to purchase")
return true
} catch (err) {
await report("Card not in stock")
await page.waitForTimeout(config.refresh_time * 1000)
return false
}
}