Issue
I have a script that reads the links that are in excel file, it opens each link fine, but when it encounters an error in automatic it marks error and closes the script. How can I make the script continue to open the links without stopping on the page that has an error?
I accept any suggestion or improvement for script in general. It's just a part of my code.
for url in mylist:
driver.get(url)
driver.maximize_window()
driver.implicitly_wait(val)
timestamp = datetime.datetime.now().strftime('%d_%m_%Y')
driver.save_screenshot(str(shark)+"/"+str(cont)+'_'+timestamp+'.png')
cont += 1
Solution
Wrap up your code block in a try-except{}
block as follows:
for url in mylist:
try:
driver.get(url)
driver.maximize_window()
driver.implicitly_wait(val)
timestamp = datetime.datetime.now().strftime('%d_%m_%Y')
driver.save_screenshot(str(shark)+"/"+str(cont)+'_'+timestamp+'.png')
cont += 1
except:
continue
Answered By - DebanjanB
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.