4

As far as I know there is no straight keyword to open new tab in selenium2library. I have seen the below code which opens a new tab in IE(default browser)for the given URL

webbrowser.open_new_tab(url)

But I want to write a keyword which opens a new tab on current running browser (it may be any browser).

TylerH
  • 20,799
  • 66
  • 75
  • 101
PKR
  • 189
  • 1
  • 4
  • 11
  • See [this](http://stackoverflow.com/questions/1689861/browser-detection-python-mod-python) question. Similarly use `HTTP_USER_AGENT` to return the browser name. Say it returns 'firefox', then pass it to `current_browser = webbrowser.get('firefox')` and `current_browser.open('http://www.google.com')` and this will automatically open up a new tab (if possible) in the open browser. Hope this helps. I'm not sure if it will work, which is why I do not post it as an answer. – Shyam K Jan 09 '13 at 12:36

4 Answers4

7

You can try

Execute Javascript    window.open('')
Get Window Titles
Select Window    title=undefined
Go To   ${URL}

This Code helps to Open New tab in the same browser and collect the Windows Title of all tabs in same browser. Based on the Window Title name , it identifies the Newly opened tab and launch the URL

nithya a
  • 103
  • 1
  • 5
  • 1
    This is a working answer. The `Execute Javascript window.open('')` can be replaced with the new SeleniumLibrary keyword, `Press Keys None CTRL+T` to open the new tab in a more elegant way. – Bence Kaulics Apr 24 '19 at 14:40
3

You can use the Javascript Keyword

Execute Javascript   window.open('NewTabUrl');

Example:

Execute Javascript   window.open('https://www.google.com');
TylerH
  • 20,799
  • 66
  • 75
  • 101
Mcvires
  • 41
  • 1
2

It's sloppy, but you can try:

from selenium.webdriver.common.keys import  Keys 

actions.key_down(Keys.CONTROL)
element.send_keys('t')
actions.key_up(Keys.CONTROL)

I'm not aware of a browser-agnostic method.

After opening a new tab you can change tabs by finding the window handle with driver.window_handles and switching to the appropriate handle: browser.switch_to_window(handle)

TylerH
  • 20,799
  • 66
  • 75
  • 101
That1Guy
  • 7,075
  • 4
  • 47
  • 59
0

You can use an AutoIt Library For Simulating KeyStroke in Robot Frame Work

Import AutoItLibrary
Import Selinium2library

send  "^t"  Open the New Tab

same way simulate others

Ctrl+Tab – Switch to the next tab – in other words, the tab on the right. (Ctrl+Page Up also works, but not in Internet Explorer.)

Ctrl+Shift+Tab – Switch to the previous tab – in other words, the tab on the left. (Ctrl+Page Down also works, but not in Internet Explorer.)

Ctrl+W, Ctrl+F4 – Close the current tab.

Ctrl+Shift+T – Reopen the last closed tab

TylerH
  • 20,799
  • 66
  • 75
  • 101