I failed to open new tab with required URL by driver.execute_script("window.open('URL');").
Therefore I changed my mind.
Any link will start on the new tab if we consider switching the current window to the new one. And I will open the new tab by driver.get(URL). The only method I need to use is driver.switch_to_window(driver.window_handles[1]).
We simply switch the window to the main window, when we close the new tab:driver.switch_to_window(driver.window_handles[0]) or driver.switch_to_window(main_window)
By the way, it will raise an error if we don't switch to the main window after closing the new tab.
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("http://www.google.com/")
# save main_window
main_window = driver.current_window_handle
# obtain url of gmail on the home page of Google
addr = driver.find_element_by_xpath('//*[@id="gbw"]/div/div/div[1]/div[1]/a').get_attribute("href")
# open new blank tab
driver.execute_script("window.open();")
# switch to the new window which is second in window_handles array
driver.switch_to_window(driver.window_handles[1])
# open successfully and close
driver.get(addr)
driver.close()
# back to the main window
driver.switch_to_window(main_window)
driver.get(addr)
ChromeWebDriverdoesn't support keys combinations