Python Forum
stop cycle while - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: stop cycle while (/thread-26869.html)



stop cycle while - windows11 - May-16-2020

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



RE: stop cycle while - deanhystad - May-16-2020

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")