We are launching a Browser from our Python back-end code. This opens a 3rd party's URL , where the user needs to submit a form. After submitting the form , the browser instance should close automatically. We tried from Python's side but it is not possible to manage the state from back-end.
Can we write some Javascript wrapper at front end to handle this?
You can't.
Javascript can't close the browser from inside or it will be tricky
Unfortunatly, if you don't have access to the 3rd party js code or an API informing you that request has been submitted, you can't even know when the user has submitted the request.
Switching on window.close(), if your application is opening only one window, you can use the:
window.close()
method. This method will close the current window. So, if you have only one opened window with Chrome (for example), the browser will be closed.
If you have multiple windows opened, only the window where the function is executed will be closed.
Related
I am using the latest version of selenium web driver and google chrome browser.
In my app, after clicking on login button while dom is getting loaded I get a popup
image
I just want to close this popup without entering any value. I am using java for scripting.
I tried javascript executor, all popup handlers from selenium but not able to close the same. I am not able to shift control on the popup window.
I google a lot but didn't found any relevant code
This is a default behavior when using HTTP basic authentication. To stop this window to come you would need to send user and password in the request. Or as I understand from other response I found about this you can write:
driver.get("http://UserName:Password#Example.com");
There seems to be a similar issue, going on in thread: How to handle authentication popup with Selenium WebDriver using Java
If all you want to do is "Cancel" the popup, instead of entering credentials. You may be able to just use this.
driver.switchTo().alert().dismiss();
using AutoID was able to resolve above issue.
Refernce: http://learn-automation.com/handle-windows-authentication-using-selenium-webdriver/
I am using Django v1.10 for an application where in need to send an API call just before browser close through crude javascript (don't want to use any library for sake) preferably. I've read about window.unload and window.onbeforeunload. The first one didn't seem to work at all. The second can work but it also gets executed when there is reload or redirection to another page (it works as it should but that is what I don't want). I've tried using SESSION_EXPIRE_AT_BROWSER_CLOSE of Django which works only when a user has totally exit out of the browser (no browser process running). I've also seen answers on the web where people have suggested to open another window/tab of the browser through JS as the tab closes.
So in precise words, I want to make an API call just before browser tab close (not in any other situation).
Please help!
I got two browser windows on the same domain,
one is the main window and the second is small popup window.
i found this: How to Communicate between two browser windows?
but, the problem is the popup opens as event on the local computer by 3rd party software...
and i don't wish to communicate back to the server, and reading the status at the main window, for slow time issues..
i wish to transfer some data from the popup directly to the main window via JS (and close the popup right after).
the event is a VOIP new income call opened by the local phone soft dialer with parameters, and the main window is a browser CRM that will need to show incoming call status via JS on the same page, AJAX-like [only local].
p.s:
maybe there is a way to communicate between browser to windows application?, so the 3rd party software will send data to it and the application will communicate to the window
(or Firefox extension - but i prefer without the need to install more addons)...
what approach should i take? what do you think is the solution?
thanks allot. ;)
If the one browser does not open up the other browser, there is no way for the two browsers to talk through window.opener.
What you could try is storing data into localstorage and have the windows poll localstorage for changes.
Have you tried using window.opener to refer to the parent window?
If I open a popup from a page is there a way I can close that popup from a different page?
Page1->Creates and opens popup.
Page2->Closes popup.
Since you can not keep a reference to your popup window on navigation, no you can not do this. But if you use pushState to change the url of your parent window and do not actually navigate, you can do it. Just simply by using close() method you can close that popup window
Other option is using a server side script to send the close signal to you popup window
I think any well-coded browser should run each page in a sandboxed environment, so one page should not even be aware that other pages exist or are being browsed, let alone what they do to the DOM or the javascript they run.
Therefore, any solution to allow communication from two different webpages (or the same page loaded two times in the browser), would have to go via an external mechanism. If its the same page loaded two times within the same browser, they should share their localStorage, so you could use it as a way to send messages.
If not, you can always rely on an external web service to do this. The page opening the popup would have to implement a polling service to see whether it should close it, and the page attempting to close the popup would have to make an AJAX call requesting it to the server, and wait for the other page to pull the result.
It's not as easy as one line of javascript, but if you REALLY want this feature, you could implement it.
On my Flex/Actionscript app I'm using FB.login, which started giving me a blank popup after inserting credentials. On IE it still works, but from what I read, this is the cause:
Calling FB.login results in the JS SDK attempting to open a popup
window. As such, this method should only be called after a user click
event, otherwise the popup window will be blocked by most browsers.
I was thinking to show a Javascript popup and after user clicks on it execute FB.login and send data back to Actionsript. Will this work?
On Actionscript I'm simply executing:
Facebook.login(onLoginHandler,{perms:'friends_work_history'});
Now, how can I call JS and then get login data back on Actionscript?
If the blocker was the culprit, I think you wouldn't see the popup at all.
What's the structure of the code that gets the login status and then calls FB.login?
I had a similar problem. Turned out to be code in/around the FB.login callback that was causing the problem.
This is a good example of something (javascript) that works: http://developers.facebook.com/blog/post/2012/05/08/how-to--improve-the-experience-for-returning-users/