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

Script reads in stock due to incorrect class selector

Open slashdotblake opened this issue 4 years ago • 6 comments

Program always reads item as being in stock. Then it continuously tries to add to cart.

The problematic code, "item = self.driver.find_element_by_class_name('btn-lg')" says look for btn-lg but regardless of if the item is in stock or not btn-lg is listed.

What if you searched by class name add-to-cart-button instead? Do you think this would work or does best buy use a unique style class for high demand items?


def in_stock(self):
		time.sleep(5)
		try:
			
			item = self.driver.find_element_by_class_name('btn-lg')
			#webdriver.ActionChains(self.driver).click_and_hold(self.driver.find_elements_by_class_name('btn btn-primary btn-lg btn-block btn-leading-ficon add-to-cart-button')).perform()
			#webdriver.ActionChains(self.driver).release().preform()
			print("In stock!")
			return True
			

		except:
			print("Item is out of stock")
			return False

slashdotblake avatar Nov 23 '20 21:11 slashdotblake

Program always reads item as being in stock. Then it continuously tries to add to cart.

The problematic code, "item = self.driver.find_element_by_class_name('btn-lg')" says look for btn-lg but regardless of if the item is in stock or not btn-lg is listed.

What if you searched by class name add-to-cart-button instead? Do you think this would work or does best buy use a unique style class for high demand items?

def in_stock(self):
		time.sleep(5)
		try:
			
			item = self.driver.find_element_by_class_name('btn-lg')
			#webdriver.ActionChains(self.driver).click_and_hold(self.driver.find_elements_by_class_name('btn btn-primary btn-lg btn-block btn-leading-ficon add-to-cart-button')).perform()
			#webdriver.ActionChains(self.driver).release().preform()
			print("In stock!")
			return True
			

		except:
			print("Item is out of stock")
			return False

Did you figure this out? Very interested.

ozeitis avatar Nov 24 '20 19:11 ozeitis

I’ve tried this but depending on the page it could have multiple add to cart buttons, so the btn-large was the best approach I could find. I’m in session at my university so I have had little time to work on the bot. I will try to get some updates out soon.

Konyanj0278 avatar Nov 24 '20 19:11 Konyanj0278

I’ve tried this but depending on the page it could have multiple add to cart buttons, so the btn-large was the best approach I could find. I’m in session at my university so I have had little time to work on the bot. I will try to get some updates out soon.

Hmm maybe you can add a setting that we chance based on location? With instructions of course haha.

ozeitis avatar Nov 24 '20 20:11 ozeitis

I’ve also considered that but from what I saw it’s pixel by pixel and because everyone has a different screen resolution it would cause some to work and others not to. I just need to find an identifier that’s universal

Konyanj0278 avatar Nov 24 '20 20:11 Konyanj0278

I’ve also considered that but from what I saw it’s pixel by pixel and because everyone has a different screen resolution it would cause some to work and others not to. I just need to find an identifier that’s universal

Another fix can be even if in stock every X tries (can be configurable) it refreshes regardless. This fixes the need to check if in stock or not in stock. Hope this helps in some way.

ozeitis avatar Nov 24 '20 20:11 ozeitis

And the program can know to continue if the product was SUCCESFULLY added to the cart.

ozeitis avatar Nov 24 '20 20:11 ozeitis