Selenium Authentication Popup preventing driver close or quit - c#

I have a selenium automated task setup to login to a website to retrieve some information. It's very basic in the automation. Just logging in and clicking two links. I am running into an issue that is proving to be a problem.
The site in question uses the Authentication Required popup which is not a javascript popup but rather the regular windows auth popup. From what I have read this isn't handled out of the box with selenium.
I am using the "http://Username:Password#url.com" to get to the site but every now and then the site itself has issues on their end where it will prompt me again from username/password randomly. Sometimes I have to enter the username/password twice in a row when navigating there by hand.
Since my task just loops continuously for a few hours picking up the needed info I figured I would just use WebDriverWait to verify an element is present on the page. If the authentication popup appears, the element isn't present. No need to care about this run, so just start over.
The problem I am having is that when the Authentication popup is displayed and I hit my timeout limit I want to close the driver/browser window so that I can start the task over again. However, driver.Close() and driver.Quit() are not doing anything. The browser remains open and the unloaded page is still there with the login popup.
Is there anyway I can force close this? Switch focus to the browser window then force close?

The Alert Method, authenticateUsing() lets you skip the Http Basic Authentication box. The below code was tested on Google Chrome in java.
Alert alert = driver.switchTo().alert();
alert.authenticateUsing(new UserAndPassword(Username, Password));
In case it doesn't work and you might want to try this:
https://stackoverflow.com/a/40757504/7071055

Related

Windows Credentials dialog won't show when navigating using axWebBrowser

I'm doing some maintenance work on a legacy app that is using AxSHDocVw.AxWebBrowser to access in an intranet website. The web site required Windows Authentication. When I navigate to the page directly using IE I get a pop-up asking for Active Directory credentials, but when I try to WebBrowser.navigate() to it I immediately get:
Refreshing the page using the provided link gives me an UNAUTHORIZED response.
Is there something I need to do when setting up the AxWebBrowser control so that it properly displays the credential popup?
Okay, found the answer, and as usual it's a coding issue. The original author of this code set it so that no pop-ups could happen (axwebbrowser.silent = true). He did it to prevent Javascript errors popping up (as opposed to, you know, FIXING the javascript errors), but a side effect was that the dialog box for credential entry wouldn't show up. Removal of that line fixed the issue.

Facebook Unity SDK AutoLogin?

Using version 4.3.3f1 of the Facebook plugin for Unity. Noticing a bit of a bug which is a bit of an annoyance at the moment.
Once the user has logged in, and accepted our permissions, the game continues and posts as desired. However if the game closes and then restarts, the user has to log in again.
I m not calling the log in function when we start up again, why? because that causes the momentary app switch which looks horrible and is jarring. The tooltips seem to suggest that the Init should attempt to restart with valid session data. However prior to and after calling that init function, the Access token seems to be blank. So there is no automatic login occurring.
I've tried setting that status flag to true in both the settings object, and by init via code. Neither seem to make a difference.
Is there something I'm missing to get this working?
When app is force quit, the session is cached, and the cached token remains valid. Facebook Login session should not expire until you force logout, quit session from your application (or) logout from Facebook application if you installed in your mobile. Better to logout from the app when user Quit or pressing the home button.
Try to have logout option inside your game and debug it, Remove logout option once you clear with this .. You may get better idea.
I've been using the Unity Facebook SDK and when I leave and return to the app it does remember that I've logged in. I simply check FB.IsLoggedIn which returns true and I skip over my login process. I only call FB.Login("email,publish_actions", LoginCallback); when FB.IsLoggedIn is false and they push my "Facebook Login" button.

How do I prevent returning to my site without login after closing tab with x?

I have a logout button on my site that triggers
FormsAuthentication.SignOut()
forcing the need to login again even if one uses the back button on the browser or copy/pastes the URL. However if one closes the tab by the x button of the browser and there's another tab still open, if they copy/paste the URL the page will reopen without logging in. This is a serious security problem. If the browser closed completely by closing all tabs that doesn't happen. How can I prevent returning to the URL after closing the tab even if the browser hasen't been closed completely? Is there a way of catching a javascript OnClose event that will trigger FormsAuthentication.SignOut()? I'm working in asp.net c#.
That's a browser session problem.
A browser session (in fact, the cookie which hold the session id is deleted when the browser is closed) ends only when the browser is closed. It's why you are not logout when you close only one tab without closing the whole browser.
There's no reason to logout the user when he only close a tab. This behavior is not standard on the web and users can be disoriented if you do that.
But nevermind, if you want to do that, you can write a few javascript that drop a popup to warn the user he must logout before leaving. To do that use the unload or onbeforeunload event.
Look at here to see examples :
How to create popup window when browser close
You may use javascript on window onbeforeunload event to make a call to your website and log out the user.
Wait, the user has two tabs open on your site and they click "Logout" in the one, but not in the other? Well, then they haven't really logged out - the session is still active. I see how that can be a problem. But it is not a SECURITY problem, it's just the same user that remains logged in.
Anyway, you can create, for instance, a new session variable that you fill with a value whenever the user logs in, and that you delete when the user logs out. Then in every Page_Load, check this variable, and redirect to the login page if it doesn't exist.
Might be a bit of overkill, but it's all server side and you won't need Javascript to do it.

An Issue with watin in IE6 and IE7 browsers

I automated a web mail application using watin. Usually that web mail application, log off every 15 minutes. So to avoid this, in my code i refresh the browser every 15 minutes so that it never allows the mail to log off. This code works fine with IE8 browser. But I faced 1 problem when I try this code with IE6 and IE7 browsers. After installing this automated application, whenever I try to upload a file using this mail a modal dialog window comes in which we have to select the file(to upload). In that modal dialog window, when I click on browse button it shows ‘Choose file to upload’ dialog and suddenly it closes itself within a second. I don’t know which 1 is blocking this dialog to open. This is the method being used to refresh the browser every 15 minutes:
while (true)
{
ie.Refresh();
Thread.Sleep(899999);
}
Any suggestions or help would be greatly appreciated.
Since it's a web mail application, I assume there's a web page involved?
If so, I would suggest taking that refresh loop out and using the meta refresh tag in the head of that HTML page instead:
<meta http-equiv="refresh" content="900">
That might help.
At the very least, it should tell you if your c# refresh loop is the issue.

c# Auto login to sprint

I have a project where I am trying to login to sprint and then do some screen scraping to get data about the different lines that the company controls. I have tried passing the cookies that are provided by the initial website call in the initial HttpWebRequest form post, but I do not get any cookies back that will denote user or session or anything. In fact, if I then try to use the WebClient class to get the landing page, the response url that I get back is the login page.
I think it is due to the fact that when you login, you get redirected to a page that does some processing and then redirects you to the landing page. I am passing in correct credentials and don't know where it is failing. Can anyone help me so that I do not need to use Watin or any other browser control to scrape that data as that will be too slow.
Use Selenium.
It is normally for website testing, but you easily use it for your situation.
It allows you to launch a browser and programmatically control mouse clicks and keyboard presses to do exactly what you need.
You also run xpath on the HTML to read data, or even run custom javascript on pages if you need to get more complicated.

Categories