Can I change it to if or for statement instead of Python exception?

Asked 2 years ago, Updated 2 years ago, 98 views

while True:
            try:
                driver.find_element_by_id('').click()
                break
            except:
                try:
                    scroll()
                    driver.find_element_by_id('').click() 
                    break
                 except:
                      scroll()

I want to scroll until I find the element and click it Can't we make it an if or for statement instead of making an exception?

What is the best way?

python exception-handling

2022-09-22 18:21

1 Answers

Try the recursive function that calls and repeats itself. If you change the code below and apply it properly, it will work as you intended.

def click(toClick):
    try:
        driver.find_element_by_id(toClick).click()
        return
    except:
        scroll()
        click(toClick)


2022-09-22 18:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.