alexa
Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry

Skip clicking on an element in the While loop, when opening a popup with selenium. Problem with While loop in python

Skip clicking on an element in the While loop, when opening a popup with selenium. Problem with While loop in python

you should approach catching the exception and, Instead of the try-else wrapping the while iteration, do it the other way round.

 while i <= limit:
    try:
        row = wait.until(EC.visibility_of_element_located((By.XPATH, f"(//div[@data-visualcompletion='ignore-dynamic' and not (@role) and not (@class)])[{i}]")))
        add = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Add Friend']"))).click()
        
        driver.execute_script("arguments[0].scrollIntoView(true);", row, add)
        time.sleep(delay)


    except ElementClickInterceptedException:
        print("A button cannot be pressed. You go to the next button ...")
    
        close_popup = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Ok']"))).click()
    i = i + 1

238 0
7

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online