desired_tab = driver.current_window_handle  #storing the handle in a variable
if driver.current_window_handle != desired_tab:
   driver.switch_to_window(desired_tab)  #switching to the tab in case it's not