Konyanj0278 / BestBuy-Automated-Checkout

A bot to constantly run and purchase item on BestBuy.com
GNU General Public License v3.0
49 stars 24 forks source link

Script reads in stock due to incorrect class selector #8

Open slashdotblake opened 3 years ago

slashdotblake commented 3 years ago

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
ozeitis commented 3 years ago

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.

Konyanj0278 commented 3 years ago

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.

ozeitis commented 3 years ago

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.

Konyanj0278 commented 3 years ago

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

ozeitis commented 3 years ago

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 commented 3 years ago

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