Python Forum

Full Version: stop cycle while
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello people, I dont know how to stop/pass this cycle while.
the situation is the next:
In one web page I need to click few times until reload the next page.

the problem is when go for the next webpage, i dont know why, but the python dont go out from the cycle while, and of course he can´t find the "find_element_by_xpath(f[i])" and have a error in "element1=driver.find_element_by_xpath(f[i])" because I can´t find the xpath


while True :
			try:

				element1=driver.find_element_by_xpath(f[i])
				driver.find_element_by_xpath(f[i]).click()
				import time
				time.sleep(1)
			except ValueError:
				print("no more clicks")

			pass
Why would you expect the while loop to end? "while True" runs forever and there is no code to break out of the while. You could try writing your code like this:
try:
    while True :
        element1=driver.find_element_by_xpath(f[i])
        driver.find_element_by_xpath(f[i]).click()
        import time
        time.sleep(1)
except ValueError:
    print("no more clicks")