I am trying to extract the numbers from the below page but always showed an exception, I tried various solutions but still get StaleElementReferenceException, here is my code..
I tried sleep and wait...., what is the problem?, please
options = Options()
options.add_argument("start-maximized")
webdriver_service = Service('C:/Users/Lenovo/PycharmProjects/pythonProject/chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 20)
driver.get("https://ec.europa.eu/ecat/category/en/5/dishwasher-detergents")
products = []
num_pages = 7
step = 0
while (step < num_pages):
try:
time.sleep(2)
elm = wait.until(EC.presence_of_all_elements_located((By.XPATH, "//*[@id='producersTableId']/tbody/tr/td[4]")))
time.sleep(2)
products.extend(elm)
for i in products:
print(i.text) # the exception appreas here
elm = wait.until(EC.presence_of_all_elements_located((By.XPATH, "//*[@id='producersTableId']/tbody/tr/td[4]")))
next_Butt = wait.until(EC.element_to_be_clickable((By.XPATH, "//*[@id='producersTableId_next']/a")))
driver.execute_script("arguments[0].click();", next_Butt)
time.sleep(2)
step += 1
except exceptions.StaleElementReferenceException as e :
print(e)
pass
print(len(products))