Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
stop cycle while
#1
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

Reply
#2
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")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to cycle through a list of charcters pooky2483 12 533 Sep-28-2020, 06:55 AM
Last Post: pooky2483
  <while> cycle is not interrupted when using the <random>module ShityCoder 3 315 Sep-04-2020, 04:05 PM
Last Post: ShityCoder
  Cycle of numpy variables Zero01 0 233 Jul-31-2020, 11:58 AM
Last Post: Zero01
  Occurrences using FOR and IF cycle P86 2 594 Jul-29-2019, 04:37 PM
Last Post: ThomasL
  pool map cycle skorost5 5 1,018 Apr-07-2019, 09:21 AM
Last Post: skorost5
  lifetime cycle counter Ibizibbik 0 980 Mar-07-2018, 07:26 PM
Last Post: Ibizibbik

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020