ElementClickInterceptedException: Message: element click intercepted in a while loop

Viewed 80

I'm writing a while loop to get jupyter to return me a list of pdf websites by clicking the download buttons in this link here : https://responsiblesoy.org/public-audit-reports?lang=en

I already have a code that clicks the search button to show all the download buttons, but when I run a while loop to "click" the button, the error in the title shows.

Next, how do I write the while loop so that it clicks all the download buttons to the bottom of the page (in my code, I used i<7 to download the 1st to 6th link)

Below is my code:

from selenium import webdriver


import requests
import time
import os


driver = webdriver.Chrome()
driver.maximize_window() 
driver.implicitly_wait(30)
driver.get("https://responsiblesoy.org/public-audit-reports?lang=en")

button=driver.find_element("xpath",'/html/body/div[1]/div[2]/div/div/div[1]/div/div/div/div[2]/div/div/div/div/form/div/div[4]/input')
button.click()
time.sleep(10)


    



list = []
i = 2

while i <7 :
        driver.maximize_window()
        button = driver.find_element("xpath",'/html/body/div[1]/div[2]/div/div/div[1]/div/div/div/div[2]/div/div/div/div/div[2]/div[{}]/div/div[4]/a'.format(i))
        window_before = driver.window_handles[0]
        button.click()
        window_after = driver.window_handles[1]
        driver.switch_to.window(window_after)
        print(driver.current_url)
        list.append(driver.current_url)
        driver.close()
        driver.switch_to.window(window_before)
        i += 1
 
print(list)

Error that I got

0 Answers
Related