Seeking to initiate a new incognito browser session from an existing chrome driver in Selenium using C#.
Various methods have been attempted, such as constructing actions to send keys like Ctrl+Shift+N to open the new incognito window for later handle swapping.
((IJavaScriptExecutor)_driver).ExecuteScript("window.open();");
_driver.SwitchTo().Window(_driver.WindowHandles.Last());
The above successfully opens a new tab within the same window, but the JavaScript code required to launch a separate browser remains unknown.
Actions action = new Actions(_driver);
action.KeyDown(Keys.Control + Keys.Shift + "N").Build().Perform();
Additionally,
action.SendKeys(Keys.Control + Keys.Shift + "N").Build().Perform();
or using multiple commands like
action.KeyDown(Keys.Control).KeyDown(Keys.Shift).SendKeys("N").Build().Perform()
The JavaScript snippet worked as anticipated previously, though it's not aligned with my current objective. The send keys method appeared ineffective altogether.