Hello Rohan, you can use the following lines of code to switch different browser tabs using Python Selenium Webdriver:
import selenium.webdriver as webdriver
import selenium.webdriver.support.ui as ui
from selenium.webdriver.common.keys import Keys
from time import sleep
browser = webdriver.Firefox()
browser.get('https://www.google.com?q=python#q=python')
first_result = ui.WebDriverWait(browser, 15).until(lambda browser: browser.find_element_by_class_name('rc'))
first_link = first_result.find_element_by_tag_name('a')
main_window = browser.current_window_handle
first_link.send_keys(Keys.CONTROL + Keys.RETURN)
browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.TAB)
browser.switch_to_window(main_window)
sleep(2)
browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 'w')
browser.switch_to_window(main_window)
Hope this Helps!!
To learn more, join the online course to do Masters in Python.
Thanks!