我有一个循环,它获取项目列表并在它们上运行各种函数...
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() 添加一个 try 异常,因此如果由于任何原因在运行此操作时超时(已知会这样做),那么它将跳出循环并移至下一个迭代。
我尝试过使用break,但这不起作用,因为我不在循环中,有人可以帮忙吗?
更新
这是我收到的超时消息
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.
最佳答案
据我了解,这就是您想要实现的目标:
from selenium.common.exceptions import TimeoutException
for i, item, in enumerate(item_list):
try:
check_item(item)
except TimeoutException:
pass # do nothing, TODO: log?
关于Python Selenium 超时移至循环中的下一项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36531283/