PKR
PKR

Reputation: 187

How to open a new tab in same browser using robot frame work

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).

Upvotes: 4

Views: 25496

Answers (4)

nithya a
nithya a

Reputation: 103

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

Upvotes: 7

That1Guy
That1Guy

Reputation: 7233

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)

Upvotes: 2

YS Kumar
YS Kumar

Reputation: 1

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

Upvotes: 0

Mcvires
Mcvires

Reputation: 41

You can use the Javascript Keyword

Execute Javascript   window.open('NewTabUrl');

Example:

Execute Javascript   window.open('https://www.google.com');

Upvotes: 3

Related Questions