Home > database >  How can call the function when achieve the condition?
How can call the function when achieve the condition?

Time:11-04

How can I call the function when achieve the condition. I made some function, but the function just call once time. It is not be able to use next time, unless I run the coding again.

If I just have one function, it is able to call, when achieve a certain condition.


def once():
    ret = False 
    while True:
      if driver.find_element(By.ID, "ONCE"):
         driver.refresh()
         ret = True
    return ret

once()

def twice():
    ret = False
    element = driver.find_element(By.ID, "Twice")
    while True:
       if driver.find_element(By.ID, "Twice"):
          elmenet.click()
          ret = True
    return ret

twice()

I expect that the function can call automaically when achieve the condition.

But I don't how to do.

For example,

when I achieve the condition, the def will call automaically.

CodePudding user response:

you can use while loop while loop will keep running until the condition is true and will stop when it is false

x=10
def PRINT(): 
    print(str(x)   ' is greater than 0')
while x > 0 :
    PRINT()
    x=x-1
  • Related