Login popup and Selenium

4.1k views Asked by At

I'm trying to access a website to start my Selenium scripting. However as soon as i put the website's link it pops up a window asking for username and password.

I can't do anything with Selenium. See what i tried in the code and that obviously didnt work out.

Any ideas?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
using System.Collections.ObjectModel;
using System.Threading;
using System.IO;
using OpenQA.Selenium.Interactions;

namespace CRMTest1WithSelenium
{
    class Program
    {
        static void Main(string[] args)
        {
            IWebDriver driver = null;
            driver = new FirefoxDriver();
            string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes("USERNAME" + ":" + "Password"));

            String URL = "http://" + credentials+ "@" + "bfaz-testcrm.cloudapp.net/BathfitterCRMTest";

            driver.Navigate().GoToUrl(URL);
            driver.Manage().Window.Maximize();


        }
    }
}
2

There are 2 answers

0
NanoMage On

You can use the selenium.actions library to hit this. I am more of a python person than c#, but the details are here: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/interactions/Actions.html

This will let you hit the 'action dialog boxes' to enter the credentials.

Unfortunatly most browsers are now having problems with these. For instance hitting the url with something headless like python-requests will let you bypass it: (Sorry the responses are in python, however i think the premiss is the same)

r = requests.get('https://username:[email protected]

Where as this should be similar using webdrivers for Firefox/Chrome with: a = driver.get('https://username:[email protected]')

However if you watch the browser, it will pass the URL correctly, yet still show the dropdown where the standards dictate that it should qualify.

Action Chains are your best bet to deal with this problem for http authentication.

0
Andrew_STOP_RU_WAR_IN_UA On

If you mean HTTP Basic Authentication

enter image description here

, your solution written here:

Handling Windows authentication with Selenium Webdriver