How can I open a new window and close the previous one, then open again another window and close the previous one. The number of links is indeterminate.
urls = ["https://www.oxxo.com/",
"https://pypi.org/project/fake-useragent/",
"https://www.youtube.com/"]
for posts in range(len(urls)):
print(posts)
driver.get(urls[posts])
driver.implicitly_wait(val)
timestamp = datetime.datetime.now().strftime('%d_%m_%Y')
chars = [':','/','%']
image_name = driver.current_url
for char in chars:
image_name = image_name.replace(char,'_')
driver.save_screenshot(str(cont)+'_'+image_name+'_'+timestamp+'.png')
cont += 1
if(posts!=len(urls)-1):
driver.execute_script("window.open('');")
chwd = driver.window_handles
driver.switch_to.window(chwd[-1])
driver.close()