So I have a test case: When clicking a button a new window is opened. To switch to that new window I use:
window_after = self.driver.window_handles[1]
self.driver.switch_to.window(window_after)
When I execute the test case in normal Chrome browser, there is no error and I receive a positive outcome. But when I use headless Chrome, I'm getting an error: "selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//h1[text()='Trip Terms and Conditions']" (Session info: headless chrome=78.0.3904.87)" This is how I use the headless Chrome:
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
driver = webdriver.Chrome(options=chrome_options)
So as I understand, headless Chrome can't switch to the new opened window. Is there a error in the code? What I'm doing wrong?
Thank you.