python - Switch back to parent tab using selenium webdriver -


I've written a sample code but it's not working. Also saw that there are only 1 window handle for 2 tabs, how to switch to the parent tab again?

  driver = webdriver.firefox () driver.set_page_load_timeout (60) driver.implicitly_wait (15) driver.get ("https://www.google .co.in body") print ' New tab opened 'driver.get ("http://gmail.com/") Print driver ") oldtab = driver.current_window_handle oldtab print driver.title body = driver.find_element_by_tag_name (print". Title print' back from old tab ' Print driver.title for handle in switch_to_window (oldtab) driver.window_handles: print "handle =", handle  

Before you switch to handle on the parent tab, Keys .

 selenium.webdriver.common.keys Import key driver from  = webdriver.firefox () driver.set_page_load_timeout (60) driver.implicitly_wait ( 15) # The first tab driver.get (in "https://www.google.co.uk") oldtab = driver.current_window_handle print driver.title time.sleep (3) # second tab driver.find_element_by_tag_name ("body"). Send_keys (Keys.CONTROL + "T") driver.get ("http://gmail.com/") newtab = driver.current_window_handle print driver.title time.sleep (3) # first tab driver.find_element_by_tag_name ("body" ). Send_keys (Keys.ALT + Keys.NUMPAD1) driver.switch_to_window (oldtab) print driver.title time.sleep (3) # again to the second tab driver.find_element_by_tag_name (Go "Body"). Send_keys (keys.ALT + keyss.NUMPAD2) driver.change_to_window (newtab) print driver.title time.sleep (3)  

Comments