0

I know there are ways of opening new tab by simulating Ctrl+T key combination, but it is not very reliable. We have sporadic test automation failures

    WebElement element = m_webDriver.findElement(By.tagName("body"));
    element.sendKeys(Keys.CONTROL + "t");

Is there a better way of doing that (more reliable)?

vmg
  • 9,920
  • 13
  • 61
  • 90
  • 1
    If you want to open a new tab, then aren't you testing the browser? Why would you do that? Just use `IWbegDriver.Navigate()` and let Selenium care about tabs, windows, new instances and all that. – Paul Hicks Jun 06 '16 at 23:04
  • 1
    Have you tried this solution: http://stackoverflow.com/a/27203079/2431110 ? – Dmitriy Khudorozhkov Jun 06 '16 at 23:06
  • @PaulHicks that is very strong statement, there are cases when this is needed, and my case is one of them. – vmg Jun 07 '16 at 01:35
  • @DmitriyKhudorozhkov thanks, I will try, looks like it will work. Still it feels like workaround though – vmg Jun 07 '16 at 01:35
  • 1
    Opening a new tab is a browser is _always_ testing the browser, not your application. Whether a new page is opened in a new window, a new tab, or in the current tab should matter not-a-whit to your application or your tests. – Paul Hicks Jun 07 '16 at 01:53
  • well, I have a piece of functionality in my app that cares about some shared session state (encryption-related). And to test it I need to be able to open some page it two tab simultaneously, in particular order, and perform interactions in particular order. "should matter not-a-whit to your application" is just a theory and in reality there is a variety of cases when this is needed. Of course, you may consider others who ask "how to open new tab in selenium" wrong, but this theory does not align with my reality. – vmg Jun 07 '16 at 16:10

0 Answers0