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

拥有回忆 提交于 2019-12-07 16:28:57

问题


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


回答1:


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)




回答2:


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




回答3:


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




回答4:


You can use the Javascript Keyword

Execute Javascript   window.open('NewTabUrl');

Example:

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


来源:https://stackoverflow.com/questions/14232137/how-to-open-a-new-tab-in-same-browser-using-robot-frame-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!