i am using selenium to open a site but inside site there is a hyperlink that opens a new tab. how can i take screenshot of that newly opened tab by navigating to it.
eg
import selenium.webdriver
import selenium.common
options = selenium.webdriver.firefox.options.Options()
# options.headless = True
with selenium.webdriver.Firefox(options=options) as driver:
driver.get('url')
time.sleep(2)
root=driver.find_element_by_tag_name('html')
root.screenshot('full page screenshot
But it does not work with new opened tab
CodePudding user response:
You need to switch to that window/tab to interact with it. how-to-switch-to-new-window
driver.switch_to.window(driver.window_handles[1]) #1 being the second window