2016-04-10 17 views
1

我有一個循環,需要的項目清單,並對其運行各種功能...Python的硒超時移動到下一個項目在環

def init_driver(): 
    ffprofile = webdriver.FirefoxProfile("my_profile"); 
    ffprofile.add_extension(extension="myaddon.xpi") 
    return driver 

def check_item 
    print ("Checking Item : ") 
    inputElement.submit() 
    print ("Submit has been pressed") 
    input(" Do Something Else ") 
    timeelapsed = a + 1 

driver = init_driver() 

for i, item, in enumerate(item_list): 
    check_item(item) 

我想一試特例到inputElement.submit (),所以如果出於任何原因它在運行時(它已知的情況下)超時,那麼它將跳出循環並移到下一次迭代。

我嘗試過使用break但是不起作用,因爲我不在循環中,任何人都可以幫忙嗎?

UPDATE

這是超時消息,我得到

File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response 
    raise exception_class(message, screen, stacktrace) 
selenium.common.exceptions.TimeoutException: Message: Timed out waiting for page load. 
+0

難道你還發布瞭如何它是否超時 - 你得到什麼錯誤? – alecxe

回答

1

據我瞭解,這是你想達到什麼目的:

from selenium.common.exceptions import TimeoutException 

for i, item, in enumerate(item_list): 
    try: 
     check_item(item) 
    except TimeoutException: 
     pass # do nothing, TODO: log? 
+0

看起來不錯,但我收到錯誤:TimeoutException未定義。我已經將原來的超時消息添加到了 – fightstarr20

+1

@ fightstarr20當中,添加了import語句 – alecxe

相關問題