Got info are same - selenium python

Viewed 44

I use python, selenium. I've tried to get some information from elements by XPath, but got info except url are same (information of next element is same to previous element). Each element have different info. I can't understand my error.

Below, I add code of functions with problems.

Main Function

def GetGifts(self):
        els = self.driver.find_elements(By.XPATH, 
                "//div[{}]/div".format(XPathL.GetByEndClassN("DivGiftWrap")))

        print("lel", len(els))
        gifts = {}
        
        for el in els:
            # print(el.get_attribute('innerHTML') + "\n")
            try: 
                url =   el.find_element(By.TAG_NAME, "img").get_attribute("src")
                name =  el.find_element(By.XPATH, "//div[{}]".format(XPathL.GetByEndClassN("DivGiftName"))).text
                price = el.find_element(By.XPATH, "//div[{}]".format(XPathL.GetByEndClassN("DivGiftCoins"))).text
            except Exception as e:
                print("e: ", e)
                continue
            
            try:
                price = int(re.search(r"\d+", price).group(0))
            except Exception as e:
                print("e2: ", e)
                continue
                        
            gifts[url] = {
                'name': name,
                'price': price,
            }
            
            
        return gifts

GetByEndClassN function

def GetByEndClassN(name):
    return "contains(concat(normalize-space(@class), ' '), '{} ')".format(name)

source of page: https://drive.google.com/file/d/11PDYscrB6wTOMwkrlcBINCdl1kz4RgVD/view

Very grateful to you for your help.

0 Answers
Related