I am trying to click on a specific color then click buy button, I find color and can click on them, but buy element can not be found. I try some locator like XPATH, CSS_SELECTOR and others.
from selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECimport timedriver = webdriver.Edge() driver.maximize_window()driver.get("https://www.digikala.com/product/dkp-4645665/") try: main_div = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.CSS_SELECTOR, "div.flex.lg\\:flex-wrap.overflow-x-auto.px-5.lg\\:px-0")) ) child_elements = main_div.find_elements(By.CSS_SELECTOR, "div.bg-neutral-000.flex.items-center\ .justify-center.cursor-pointer.ml-2.px-2.lg\\:px-0.styles_InfoSectionVariationColor__pX_3M") specific_value = "سفید" add_to_cart= WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.CSS_SELECTOR, "button[data-testid='add-to-cart']")) ) for child in child_elements: time.sleep(1) if child.text == specific_value: add_to_cart.click() breakexcept Exception as e: print("Exception:", e)finally: driver.quit()