i am running the below code to webscrape a site in python using selenium:
def click_and_wait_for_additional_info(elem):
# Click on the store element to navigate to its individual page
elem.click()
time.sleep(2)
try:
features = driver.find_element(By.XPATH, '//*[@id="QA0Szd"]/div/div/div[1]/div[3]/div/div[1]/div/div/div[2]/div[6]/button/div[2]/div/div').text
except:
features = "None"
return features
everytime i run this code on large number of observations, it gives error ElementClickInterceptedException
Any suggestions how this can be handled?
i tried below: a)driver.implicit wait b) below code:
def click_and_wait_for_additional_info(elem):
try:
# Wait for the element to be clickable
clickable_elem = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//div[@class="Nv2PK tH5CWc THOPZb "]')))
# Click on the store element to navigate to its individual page
clickable_elem.click()
time.sleep(2)
try:
features = driver.find_element(By.XPATH, '//*[@id="QA0Szd"]/div/div/div[1]/div[3]/div/div[1]/div/div/div[2]/div[6]/button/div[2]/div/div').text
except:
features = "None"
return category
except ElementClickInterceptedException:
print("Element click intercepted. Retrying...")
# Retry clicking on the element
try:
clickable_elem = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//div[@class="Nv2PK tH5CWc THOPZb "]')))
clickable_elem.click()
time.sleep(2)
# Your code to extract additional info goes here...
except Exception as e:
print("Exception occurred:", e)
return None
except Exception as e:
print("Exception occurred:", e)
return None
however in bot, while the error gets resolved, the data is: a) shiftef b) getting repeated