79267797

Date: 2024-12-10 10:08:12
Score: 3
Natty:
Report link

Thank you @Lewis for your help! Really appreciate it. Your answers helps me a lot and I did manage to simplified it according to my needs.

class AddToCart(BasePage):
  def select_item_to_add(self, numberOfItemToAdd=0):
      buttons = self.get_elements(AddToCartItem.Product_Item_Button)
      
      countOfItemsToAdd = min(len(buttons), numberOfItemToAdd)
      random_button = randint(1, len(buttons))

      if numberOfItemToAdd == 0:
         for selectedBtn, select_one_item in enumerate(buttons, start=1):
             if selectedBtn == random_button:
                select_one_item.click()
      else: 
         for selectItem in random.sample(buttons, countOfItemsToAdd):
            selectItem.click()
Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Lewis
  • Self-answer (0.5):
  • Looks like a comment (1):
  • Low reputation (1):
Posted by: aben17