Python3 goto分配为无限while循环?

时间:2019-01-16 08:22:38

标签: python-3.x loops selenium-webdriver goto

我是python新手,不了解如何在python3 / selenium中分配“ goto”标签。我知道没有,但是如何编写我的脚本以确保它不会执行无限的while循环(此处以伪代码编写)?

while True:
    for-loop1
        something happens

    for-loop2
        something else is happening

    for-loop3
        even more stuff happens

    try:
        WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "li:not(.disabled)>a[data-page='next']"))).click() # checks for other page
        print("There is another page.")
        time.sleep( 2 ) # wait to load
    except NoSuchElementException:
        print("No further page exists. Bye, bye!")
        break

driver.quit()

我收到以下错误消息:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "li:not(.disabled)>a[data-page='next']"))).click() # checks for other page
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/support/wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 

编辑:

问题已解决:

driver.find_element_by_css_selector("li:not(.disabled)>a[data-page='next']").click()

1 个答案:

答案 0 :(得分:1)

如果我正确理解了您的问题,则根本不需要使用“ goto”。您可以使用环绕在for循环中的简单while循环来解决该问题。

while True:
    for things in loop1:
        do stuff

    for things in loop2:
        do more stuff

    if there_are_no_more_pages:
        break