In Django, how can I get the response to be opened in a new window from the view?
if i do this, this will open the mynewpage.html in the original window
return HttpResponse('mynewpage')
I want to open mynewpage.html in a new window , separate from the originial.
Your server has no concept of windows - it just sends back files to the browser. You need to do this via javascript:
window.open('url to open','window name','attribute1,attribute2')
So you can either create a custom view and template whose job is to open a new window with a specified link, then return the main window to the page it was previously at, or simply open the url you want from the original window without contacting the server
Related
Good day, fellow stackoverflow users. I have a problem using Vaadin TestBench in order to test a sub-window.
To be more specific, I've programmed a "popup" window that will be invoked by the main application when such application fails for whatever reason. As this sub-window doesn't have an URL, it will simply be invoked programmatically. I'm having problems coming up with a way of testing this single sub-window, as I have searched and read the Vaadin documentation, but all examples I see involve creating a driver for a certain browser, invoking a URL, accessing its elements and then doing the tests.
All I want is something like this:
Window popup = new Window() // Create sub-window (popup) programmatically
// instead of navigating to an URL with a web driver
// Here, I select the elements of the popup and do actions on it
// programmatically
...
// End the test and close the popup window
popup.close()
Is there a way of accomplishing this feat? I'm using the latest version of Vaadin on Springboot.
Vaadin Testbench and Selenium use the same base. You can reach the popup in the same way you do in Selenium:
driver.switchTo().activeElement();
or (if it is an alert)
driver.switchTo().alert().submit(); //submit = click OK, maybe it differs from your intention
If your "popup" is a separate browser window, you can switch by windowHandle.
driver.switchTo().window();
Hope this helps :)
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).
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
You can use the Javascript Keyword
Execute Javascript window.open('NewTabUrl');
Example:
Execute Javascript window.open('https://www.google.com');
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)
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
I have a repeater which I bind the data using Bind method from the database. There is a Asp:Button with an onclientclick and onclick event. In OnClientClick I open a new window and onclick I am adding the data to the database. This works perfectly on the first Page load. After first click on any of the buttons in the repeater, the click events stops working on subsequent clicks.
I have spending hours on finding a solution for the same, can any one guide me where i am going wrong what needs to be done.
P.S: My application is AJAX Enabled , using WCF and JQUERY
Thanks & Regards,
Phani...
Never Mind I got it solved my self. For others who are trying to solve the same issue, here is the solution:
The code below opens up a new window with out popup blocker blocking the window
OnClientClick of the button write Javascript like below to open a new window and refresh the parent window (I have to do this as the ItemCommand event was not firing until the page is refreshed)
OnClientClick = "target='_blank'; setTimeout("location.reload(true);", timeout);
Phani...
I have IWebBrowser2 ctrl embedded into my own dialog. I want to simply
display a promo banner within it from my url. How to disable all popup
menu items from the control and force it to open links in new window
(currently when I click on link in the banner, it is being opened
within the same control).
Regards
Dominik
Have a look at the following article:
WebBrowser Customization
I don't know if there is a more convenient way of doing this - but you could always intercept BeforeExplorerNavigate2(), set the out-parameter cancel to true and from there either do a new Navigate() with a different target frame name or open a new window.
As Rob pointed out, there might be problem with filtering out navigate events originating from scripts, see this question.
Greetings!
Situation:
My ActiveX DLL contains a customized webbrowser. The webbrowser displays a web page. When user clicks the link within the displayed page, a new IE window pop up and navigate to the clicked link URL.
Question:
How can I capture the DocumenComplete and NavigateComplete events fired from the NEW pop up IE window?
What I already tried:
I tried to capture the
*NewWindow2(IDispatch **ppDisp,
VARIANT_BOOL Cancel)
event fired from customized webbrowser (not new IE window), and obtained the pointer ppDisp which points to the new IE windown. I tried to use this pointer as event source to advise or connect to the event handler (IDispatch::Invoke) for event capture. However it does not work. Maybe the failure is because the document in new IE window has not been loaded yet. I am not sure.
Can you please give me an suggestion what I should do?
Thanks!
You don't obtain the new web browser in ppDisp. You create one, sink events, and return its application property in ppDisp to the event.
void CYourDlg::OnNewWindow2(LPDISPATCH FAR* ppDisp, BOOL FAR* Cancel)
{
CDlgNewWB* dlgNewWB = new CYourDlg;
this.listDialogWeb.Add(dlgNewWB);
dlgNewWB ->Create(IDD_WBDLG_DIALOG);
dlgNewWB ->m_webBrowser.SetRegisterAsBrowser(TRUE);
*ppDisp = dlgNewWB ->m_webBrowser.GetApplication();
}