0

This portion of my code submits a request for sms verification. I want it to restart a portion of the script if the sms verification code is not received within 90 seconds, so it will restart that step and try for a new number.

                EC.presence_of_element_located((By.XPATH, "//*[@id='mobile-container']/div/div/form/div[2]/div[4]/div/div/div/div[2]/button")))
                time.sleep(0.5)
                addPn.click()
                time.sleep(1)
                numberBox = driver.find_element(By.XPATH, "//*[@type='tel']")

                global nId
                global num

                noNum = True
                while noNum:
                    r = requests.get("https://sms-activate.ru/stubs/handler_api.php?api_key=00000000000000000&action=getNumber&service=ew&country=0")
                    if "ACCESS_NUMBER" in r.text:
                        info = r.text.split(":")
                        nId = str(info[1])
                        num = str(info[2])
                        noNum = False

                c = driver.find_element(By.XPATH, "//*[@class='country']")
                c.click()
                z = driver.find_element(By.XPATH, "//*[@class='country']/option[38]")
                z.click()
                time.sleep(0.5)
                numberBox.click()

                for character in num[1:]:
                    numberBox.send_keys(character)
                    time.sleep(0.2)

                sendCode = driver.find_element(By.XPATH, "//*[@class='sendCodeButton']")
                sendCode.click()

                requests.get(f"https://sms-activate.ru/stubs/handler_api.php?api_key=00000000000000000&action=setStatus&status=1&id={nId}")

                code = ""

                noCode = True
                while noCode:
                    r = requests.get(f"https://sms-activate.ru/stubs/handler_api.php?api_key=00000000000000000&action=getStatus&id={nId}")
                    if "STATUS_OK" in r.text:
                        code = r.text.split(":")[1]
                        noCode = False

                codeBox = driver.find_element(By.XPATH, "//*[@type='number']")
                for character in code:
                    codeBox.send_keys(character)
                time.sleep(0.5)
                check = driver.find_element(By.XPATH, "//*[@class='checkbox']")
                check.click()
                time.sleep(0.4)

                cont = driver.find_element(By.XPATH, "//*[@value='CONTINUE']")
                cont.click()
mrhexxx
  • 11
  • 2
  • If I get you right, you want to set a timer on your while loop. Check [this](https://stackoverflow.com/questions/14742089/time-a-while-loop-python/) – RJ Adriaansen Feb 22 '21 at 00:05
  • yes so if it is not completed within 90 second, I want it to restart the sms verification section I provided. I am not sure where to add the code – mrhexxx Feb 22 '21 at 06:14

0 Answers0