[英]Python 'continue' interfering with 'try/except' or 'with'?
[英]Try Except Continue Python not working
我有以下嘗試例程:
While true:
print("back to beginning")
self.driver.get("http://mylovelywebsite.com")
try:
wait.until(
EC.title_is("This is my title")
)
except TimeoutException as ex:
print("HERE!")
print(ex.message)
self.driver.quit()
continue
它用於硒,只是等待標題是否存在。 但是,我相信這只是一個python問題(硒工作正常)
發生的問題是ex.message沒有打印出任何內容。 但是,即使我刪除了它,它也不會轉到.quit()函數,而在到達continue語句時,它只會返回到print(“ HERE!”)語句(而不是返回到開頭)。劇本。
我想知道如何制作它,以便在出現錯誤時將其返回到腳本的開頭並再次運行? 我是否必須減少continue和quit()1的縮進量? 我不確定這是否行得通,因為即使沒有捕獲到錯誤,它也會進入continue語句。
While
應while
true
應該為True
TimeoutException
沒有message
屬性; 請改用str(ex)
。 TimeoutException
則沒有顯示。 from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import TimeoutException
while True:
print("back to beginning")
self.driver.get("http://mylovelywebsite.com")
try:
wait.until(EC.title_is("This is my title"))
except TimeoutException as ex:
print("HERE!")
print(str(ex))
self.driver.quit()
continue
from selenium.common.exceptions import TimeoutException
timeOut = True
while True:
print("back to beginning")
try:
if timeOut:
raise TimeoutException("Something caused a timeout")
else:
break # leave the while loop because no error occurred
except TimeoutException as ex:
print("HERE!")
print(str(ex))
continue
無限循環; 以ctrl+c
終止。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.