
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

volunteer_url = 'https://www.innocenceproject.org/volunteer/'
thankYou_url = 'https://www.innocenceproject.org/volunteer/#thank-you'

chromeOptions = Options()
chromeOptions.add_argument("--kiosk")
driver = webdriver.Chrome(chrome_options=chromeOptions)
driver.fullscreen_window()

driver.get(volunteer_url)

def remove_header():
    element = driver.find_element_by_class_name('normal-header')
    driver.execute_script("""
    var element = arguments[0];
    element.parentNode.removeChild(element);
    """, element)

remove_header()

while True:
    if driver.current_url == thankYou_url:
        time.sleep(5)
        driver.get(volunteer_url)
        remove_header()
    elif driver.current_url != volunteer_url:
        driver.get(volunteer_url)
        remove_header()
    
    if len(driver.window_handles) > 1:
        print(len(driver.window_handles))
        for i in range(len(driver.window_handles)-1):
            print('Switch to tab')
            driver.switch_to.window(driver.window_handles[i+1])
            print('Close tab')
            driver.close()
            driver.switch_to.window(driver.window_handles[i])

