How to create diffrent sessions(tabs) in one browser and duplicating tab using IInputSimulator

I am using ChromeDriver with Selenium in my WPF desktop(.net core) application and I want to open different tabs(Sessions) in 1 Chrome browser For that I am using IInputSimulator(virtual keyboard) with the shortcut Ctrl+Shift+x but it is not opening as per the given TabCount.

Do you have any solution or alternate way to achieve the same?

Here is my code snippet:

for (var i = 0; i < TabCount - 1; i++)
{
                try
                {
                    _logger.Info($"Tab changed: i={i}, tab count:{TabCount}");
                    _driver.SwitchTo().Window(mainHandler);

                    Thread.Sleep(2500);
                    _inputSimulator.Keyboard.ModifiedKeyStroke(new[] { VirtualKeyCode.CONTROL, VirtualKeyCode.SHIFT }, new[] { VirtualKeyCode.VK_X });

                    _driver.SwitchTo().Window(_driver.WindowHandles.Last());
                    if (_driver.Url != Constant.TabUrls.Google_URL)
                    {
                        _driver.Navigate().GoToUrl(Constant.TabUrls.Google_URL);
                        Thread.Sleep(2500);
                    }
                }
                catch (Exception ex)
                {
                    _logger.Error(ex.Message, ex);
                }
                _logger.Info("Go back to main handler");
}

According to tab-window-shortcuts, there is no shortcuts for tab duplicating. Use the following instead:

driver.SwitchTo().NewWindow(WindowType.Tab);
driver.Navigate().GoToUrl(targetUrl);

Leave a Comment