BestBuy-Automated-Checkout icon indicating copy to clipboard operation
BestBuy-Automated-Checkout copied to clipboard

Erroneous In-Stock Identification

Open brbubba opened this issue 4 years ago • 58 comments

Looks like it is identifying "out of stock" state as "in stock" and then tries to add to cart.

brbubba avatar Nov 11 '20 20:11 brbubba

i don't know if that is normal operation? looks like it's operating the same way for me....maybe the OP can chime in here..

Kali123411 avatar Nov 14 '20 01:11 Kali123411

Yeah the same thing is happening to me too. It thinks its in stock and constantly tries to add to cart without refreshing the page.

DelayedRainbow avatar Nov 14 '20 01:11 DelayedRainbow

Can you guys post a picture of the output along with what sku you are using and I will look into it, chances are the webpage has changed and it cant find the element anymore. I'll make any changes needed.

Konyanj0278 avatar Nov 14 '20 02:11 Konyanj0278

output 3080

Kali123411 avatar Nov 14 '20 02:11 Kali123411

Thats the same output im getting too, im trying to get sku 6429434, thanks.

DelayedRainbow avatar Nov 14 '20 03:11 DelayedRainbow

I have made an update to the instock checking method unfortunately I am not able to test the code right now please advise if the update fixes your issues.

Konyanj0278 avatar Nov 14 '20 03:11 Konyanj0278

I have made an update to the instock checking method unfortunately I am not able to test the code right now please advise if the update fixes your issues.

It did not change, still trying to add to cart for me....not sure how you can approach this because the website button is showing it's been disabled #

Kali123411 avatar Nov 14 '20 04:11 Kali123411

I'd recommend checking the button text and taking appropriate action based on that. EX. Add to cart/Out of Stock/Sold Out.

It's widely used across all product pages for inventory state and is unlikely to change.

itemText = self.driver.find_element_by_class_name('btn-lg').text
			if itemText == 'Sold Out':
				print('Sold Out')
				return False
			if itemText == 'Add to Cart':
				print("In stock!")
				return True

You'll need to consider some logic in the case an item is not in stock or SoldOut, like refreshing the page to check again.

kmedeiros95 avatar Nov 15 '20 02:11 kmedeiros95

I created a simple logic (for now). I'm not 100% sure if it'll work on Best Buy's que/Please Wait system but it refreshes when an item is out of stock and attempts to add to cart when the yellow button says "Add to Cart". Knowing somewhat of the que system, the que system will start after clicking "Add to Cart" and Best Buy will tell you to "Please Wait". When your que is up, the "Add to Cart" button will appear. In this case, I added some logic so that the bot will stop refreshing when "Add to Cart" appears and run add_toCart in a while loop until the "Add to Cart" button reappears after the "Please Wait".

def in_stock(self):
               time.sleep(5)
		try:
			item = self.driver.find_element_by_xpath("//button[text()='Add to Cart']")
			print("In stock!")
			return True
		except:
			self.driver.refresh()
			print("Item is out of stock")
			return False

and

instock= bot.in_stock()
incart=False
if (instock==True):
	while(incart != True):
	 	incart=bot.add_toCart(incart)
else: 
	if (instock==False):
		while(instock==False):
			instock=bot.in_stock()
			if (instock==True): 
				while(incart != True):
	 				incart=bot.add_toCart(incart)

I quickly wrote this without trying to make it efficient so feel to criticize it lol

randomslap avatar Nov 15 '20 03:11 randomslap

I'd recommend checking the button text and taking appropriate action based on that. EX. Add to cart/Out of Stock/Sold Out.

It's widely used across all product pages for inventory state and is unlikely to change.

itemText = self.driver.find_element_by_class_name('btn-lg').text
			if itemText == 'Sold Out':
				print('Sold Out')
				return False
			if itemText == 'Add to Cart':
				print("In stock!")
				return True

You'll need to consider some logic in the case an item is not in stock or SoldOut, like refreshing the page to check again.

That's what I thought this program was attempting to do, left-clicking the sold out button continuously waiting for it to change to the add to cart state....would the page not automatically refresh when the add the cart button appeared?

Kali123411 avatar Nov 15 '20 04:11 Kali123411

I'd recommend checking the button text and taking appropriate action based on that. EX. Add to cart/Out of Stock/Sold Out. It's widely used across all product pages for inventory state and is unlikely to change.

itemText = self.driver.find_element_by_class_name('btn-lg').text
			if itemText == 'Sold Out':
				print('Sold Out')
				return False
			if itemText == 'Add to Cart':
				print("In stock!")
				return True

You'll need to consider some logic in the case an item is not in stock or SoldOut, like refreshing the page to check again.

That's what I thought this program was attempting to do, left-clicking the sold out button continuously waiting for it to change to the add to cart state....would the page not automatically refresh when the add the cart button appeared?

The original script simply checks if that button (Add to Cart, Sold Out, etc.) is present on the page, doesn't consider its state. When the "Add to Cart" function runs attempts to click that button.

Im not sure if the Best Buy "Add to Cart" button dynamically updates or requires a page refresh. But it's my assumption you to have to refresh the page, update the DOM and the button state if availability changes.

In the case that it does require a refresh the original script would never see the "Add to Cart" button.

kmedeiros95 avatar Nov 15 '20 12:11 kmedeiros95

I'd recommend checking the button text and taking appropriate action based on that. EX. Add to cart/Out of Stock/Sold Out. It's widely used across all product pages for inventory state and is unlikely to change.

itemText = self.driver.find_element_by_class_name('btn-lg').text
			if itemText == 'Sold Out':
				print('Sold Out')
				return False
			if itemText == 'Add to Cart':
				print("In stock!")
				return True

You'll need to consider some logic in the case an item is not in stock or SoldOut, like refreshing the page to check again.

That's what I thought this program was attempting to do, left-clicking the sold out button continuously waiting for it to change to the add to cart state....would the page not automatically refresh when the add the cart button appeared?

The original script simply checks if that button (Add to Cart, Sold Out, etc.) is present on the page, doesn't consider its state. When the "Add to Cart" function runs attempts to click that button.

Im not sure if the Best Buy "Add to Cart" button dynamically updates or requires a page refresh. But it's my assumption you to have to refresh the page, update the DOM and the button state if availability changes.

In the case that it does require a refresh the original script would never see the "Add to Cart" button.

If that is true then how does the OP claim it worked for him....things that make you go hmmmmm

Kali123411 avatar Nov 15 '20 16:11 Kali123411

I managed to get the card before I finished the bot refreshing the page was something I planned to add in but hadn’t had the chance to do so yet

Konyanj0278 avatar Nov 15 '20 17:11 Konyanj0278

I managed to get the card before I finished the bot refreshing the page was something I planned to add in but hadn’t had the chance to do so yet

Thanks for being honest, I'll keep following in case the page refresh (F5) can be implemented. Just trying to get a 3080 for myself before Cyberpunk drops...if it ever drops lol...

Kali123411 avatar Nov 15 '20 17:11 Kali123411

I managed to get the card before I finished the bot refreshing the page was something I planned to add in but hadn’t had the chance to do so yet

Thanks for being honest, I'll keep following in case the page refresh (F5) can be implemented. Just trying to get a 3080 for myself before Cyberpunk drops...if it ever drops lol...

I went in store and had them check I’d try that to

Konyanj0278 avatar Nov 15 '20 18:11 Konyanj0278

I created a simple logic (for now). I'm not 100% sure if it'll work on Best Buy's que/Please Wait system but it refreshes when an item is out of stock and attempts to add to cart when the yellow button says "Add to Cart". Knowing somewhat of the que system, the que system will start after clicking "Add to Cart" and Best Buy will tell you to "Please Wait". When your que is up, the "Add to Cart" button will appear. In this case, I added some logic so that the bot will stop refreshing when "Add to Cart" appears and run add_toCart in a while loop until the "Add to Cart" button reappears after the "Please Wait".

def in_stock(self):
               time.sleep(5)
		try:
			item = self.driver.find_element_by_xpath("//button[text()='Add to Cart']")
			print("In stock!")
			return True
		except:
			self.driver.refresh()
			print("Item is out of stock")
			return False

and

instock= bot.in_stock()
incart=False
if (instock==True):
	while(incart != True):
	 	incart=bot.add_toCart(incart)
else: 
	if (instock==False):
		while(instock==False):
			instock=bot.in_stock()
			if (instock==True): 
				while(incart != True):
	 				incart=bot.add_toCart(incart)

I quickly wrote this without trying to make it efficient so feel to criticize it lol

Thanks for this, I have tested it and it is working. Reports Item is out of stock and refreshes the page. image

Kali123411 avatar Nov 15 '20 18:11 Kali123411

So i woke up this morning to this....the bot didn't complete the checkout process...does this mean the other bots beat me to it? image

Kali123411 avatar Nov 16 '20 15:11 Kali123411

Maybe but it usually means that the website had an error when the bot tried to add it to cart, this is something I’ve seen happen a lot to people on Bestbuy website. The only way is to brute force it and it seems like it sold out

Konyanj0278 avatar Nov 16 '20 17:11 Konyanj0278

Maybe but it usually means that the website had an error when the bot tried to add it to cart, this is something I’ve seen happen a lot to people on Bestbuy website. The only way is to brute force it and it seems like it sold out

Okay, I have the programs running on two different machines for two different items. Another thing I noticed is I get a random pop-up for a survey when the page is being refreshed. I don't know if that would cause and issue if the bot was trying to add item to cart and the survey popped up...

Kali123411 avatar Nov 16 '20 17:11 Kali123411

I never encountered that when I was making the bot so I never gave it a way to close them if it happens again can you send a picture so I know at what point it came up

Konyanj0278 avatar Nov 16 '20 17:11 Konyanj0278

image I'm assuming this error occurred on the site. Maybe the bot needs a logic where if this pops up, it should refresh?

randomslap avatar Nov 16 '20 23:11 randomslap

What step was it making you do, when I made the bot Bestbuy didn’t have any form a queuing or bot detection system in place

Konyanj0278 avatar Nov 16 '20 23:11 Konyanj0278

This happens when the item is in stock and clicks add to cart. A condition might be needed in the add_toCart function where if "This Item is not in you cart yet" is present then it should refresh and try to add to cart again.

randomslap avatar Nov 16 '20 23:11 randomslap

Here is a youtube video of someone attempting to buy a RTX 3070. https://www.youtube.com/watch?v=01gGNj-nK08

randomslap avatar Nov 16 '20 23:11 randomslap

so it looks like this is not going to work if they have put anti-bot measures in place....just gonna have to do it the old fashion way and start going into stores....

Kali123411 avatar Nov 16 '20 23:11 Kali123411

Here is a youtube video of someone attempting to buy a RTX 3070. https://www.youtube.com/watch?v=01gGNj-nK08

funny how they are talking about switching to AMD....all the Ryzen 4th gen stuff is sold out too lol...I bet the RX cards will be a disaster also...

Kali123411 avatar Nov 17 '20 00:11 Kali123411

Maybe but it usually means that the website had an error when the bot tried to add it to cart, this is something I’ve seen happen a lot to people on Bestbuy website. The only way is to brute force it and it seems like it sold out

brute force should never be the answer lol

Kali123411 avatar Nov 17 '20 00:11 Kali123411

so it looks like this is not going to work if they have put anti-bot measures in place....just gonna have to do it the old fashion way and start going into stores....

It's possible. The error isn't from an anti-bot. It just requires a simple refresh whenever that error pops up after trying to add to cart. The bot can then do the same process: attempt to add to cart, error?, refresh, attempt to add to cart, etc like a loop

randomslap avatar Nov 17 '20 00:11 randomslap

The only anti bot that Best Buy has is cookie based which is only good against terminal based bots. This bot uses Selenium which utilizes the actual browser so it looks like an actual person is using it.

randomslap avatar Nov 17 '20 00:11 randomslap

The only anti bot that Best Buy has is cookie based which is only good against terminal based bots. This bot uses Selenium which utilizes the actual browser so it looks like an actual person is using it.

okay how to we get this extra step implemented in the program? somebody has to actually get a card in their cart....

Kali123411 avatar Nov 17 '20 00:11 Kali123411