Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save danyashorokh/882cbe6eabc447f3bbdce13619c4d637 to your computer and use it in GitHub Desktop.
Save danyashorokh/882cbe6eabc447f3bbdce13619c4d637 to your computer and use it in GitHub Desktop.
[Python] [Selenium] Waiting for form using Selenium
def wait_form(driver, type, path, one_time, max_time, final_text):
flag1 = 0
while (True):
if flag1 == max_time:
print(final_text + "\n")
break
driver.close()
sys.exit(1)
else:
try:
if type == "xpath":
driver.find_element_by_xpath(path).click()
if type == "id":
driver.find_element_by_id(path).click()
break
except ElementNotVisibleException: # NoSuchElementException:
time.sleep(one_time)
flag1 += 1
except NoSuchElementException:
time.sleep(one_time)
flag1 += max_time
final_text += u" - Элемент не найден\n"
if flag1 > 1:
print(u"Ожидали %d раз(а) по %d секунды" % (flag1, one_time))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment