I currently try to create a loop to click all links on a website https://www.hatvp.fr/le-repertoire/liste-des-entites-enregistrees/ one after another.
I found this part in the html code that could solve my problem: a.orga-card-row:nth-child(i) it's from the css selector, and increases with every item so (1),(2) etc., so it should be easy to create a for i in range or while loop. A earlier version with the xpath ran smoothly, but I have no clue how to create a loop with it, so this part would be a easier solution. Another problem is the variable in the call, I solved this with a str(i), but since the first part of the code doesn't work, I don't know if that's sufficient.
i=1
def wait_for_element_to_be_clickable(element):
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, element)))
element = "a.orga-card-row:nth-child("+str(i)+")"
wait_for_element_to_be_clickable(element)
driver.find_element_by_css_selector(element).click()
To create a loop to click all the links one by one on the webpage, you can modify your current approach to loop through a range of nth-child selectors. I'll provide you with a general Python code using Selenium WebDriver that should help you achieve this task. Note that you'll need to handle exceptions and possibly waiting for elements to be clickable or visible.
Here is a simplified example of how you might structure your loop:
replace max_links with the actual number of links you expect to click or implement a dynamic way to determine when to stop the loop.