from time import sleep from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() #options.add_argument('--headless') br = webdriver.Chrome(chrome_options=options) br.get("http://www.spbeen.com") abutton = br.find_element_by_xpath('//*[@id="content_show"]/div/div[1]/div[1]/div[1]/h3/a') print(abutton.get_attribute('href')) new_table_js = 'window.open("{}")'.format(abutton.get_attribute('href')) br.execute_script(new_table_js) print(br.window_handles) for i in range(0,2): br.switch_to.window(br.window_handles[i]) print(br.current_window_handle) br.close() br.switch_to.window(br.window_handles[0]) sleep(6) br.quit()