0

I'm trying to write a script to access a Cisco Wireless LAN controller. I'm using Selenium and Chrome, and I'm stuck on the login page. From what I can tell, clicking the 'login' button on the Cisco splash screen triggers a javascript called loginAction() to prompt the user for a username and password.

The problem I'm getting is that the popup login box has no identifiable elements. When the login box is displayed, the cursor is already active in the username field. It seems that I would be able to use the sendKeys function to simply enter a username in the currently active text box, but it doesn't work. Since I don't know the id of the text boxes, I can't use something like driver.findElement(By.id("authlogin")).sendKeys("username");

Looking at other forum posts, I've seen where a common solution is to embed the username and password in the URL when the browser is loaded, like driver.get('https://username:password@exampleurl.com'). I'm not having any luck with this either; it simply brings up the same splash screen and asks for credentials, just like if I had manually clicked the 'login' button on the splash screen.

Does anyone have any ideas on this? It seems like it would be fairly straightforward since the cursor is already active in the username text box. Thanks for any help and advice!

Screenshot

MLavoie
  • 9,671
  • 41
  • 36
  • 56
  • You can use Selenium to target **any** DOM structure; not just elements with IDs or classes. What does the login box's HTML structure look like? Can you update the question to showcase that please? – Obsidian Age Oct 29 '17 at 22:20
  • I can't seem to find anything about the HTML structure of the login box. I can't right-click on it and inspect the elements, and on the HTML side, all I see is the HTML for the splash screen--there's nothing there for the login box. – drummingrocks Oct 29 '17 at 22:23
  • You can always use `CTRL` + `U` to view a source, or F12 for the Developer Tools. Surely the parent (or nearby element) has a unique identifier that you can make use of. – Obsidian Age Oct 29 '17 at 22:24
  • I thought the same thing, but if it's there, I'm not seeing it. Let me post a screenshot. – drummingrocks Oct 29 '17 at 22:27
  • Added screenshot at the bottom of the post. – drummingrocks Oct 29 '17 at 22:37
  • possible duplicate https://stackoverflow.com/questions/24304752/how-to-handle-authentication-popup-with-selenium-webdriver-using-java – Stephen Thomas Oct 29 '17 at 23:22
  • Thanks Stephen, but I tried the suggestions on that site and still haven't made it work. Like someone mentioned in one of the comments on that post, it seems like Chrome doesn't treat the authentication like a regular Alert like it used to. I also looked into using driver.authenticateUsing()), which was suggested on that link, and it seems to still be in beta and only operates with IE, not Chrome. – drummingrocks Oct 30 '17 at 00:02
  • That login dialog is a browser dialog, not HTML. Post your code that you have used to try to deal with this issue. – JeffC Oct 30 '17 at 19:46

3 Answers3

0

I too faced similar issue while logging into the application. Since the windows authentication popup opened for login is not browser based popup, so selenium cannot interact with it directly. To interact with windows based popup, you have to use third party tool like AutoIT. After doing setup for AutoIT you just have to add one line of code as shown below after your url

driver.get("http://your.url");
Runtime.getRuntime().exec("D:\\AutoIt\\AutoItTest.exe");//path where you kept exe file 

For more info on how work on AutoIT, check second approach here or go through this article

Shoaib Akhtar
  • 1,393
  • 5
  • 17
  • 46
  • Thanks! I initially tried this with AutoIT before switching to Chrome/Selenium, so it will be no problem to re-purpose what I had already written for AutoIT. – drummingrocks Oct 30 '17 at 11:14
  • Didn't understood your above comment exactly. You don't want solution in AutoIT? You want to achieve it only through selenium? Or you already got the solution using AutoIT – Shoaib Akhtar Oct 30 '17 at 12:22
  • I was able to make it work in AutoIT, but I felt like it was a patched-together workaround. Even with AutoIT, I eventually go to the point where I couldn't select an element in the browser, so it came down to MouseMove() and MouseClick() to make it work. If I resize or move the browser window, it breaks entirely because the MouseMove() coordinates no longer match up. – drummingrocks Oct 31 '17 at 00:24
  • Only for login scenario you have to use AutoIT since selenium is used only for automating browser based application and can't interact with windows authentication popup. Now once you are logged into the application using AutoIT, now switch to selenium for covering test case after login. For MouseMove() and MouseClick() you can use Action class of selenium http://www.seleniumeasy.com/selenium-tutorials/how-to-perform-mouseover-action-in-selenium-webdriver – Shoaib Akhtar Oct 31 '17 at 07:12
  • Thanks. Will the Runtime.getRuntime().exec("C:\\Selenium\\script.exe"); not work in Javascript? I'm getting an error that 'Runtime is not defined' when I try to run the AutoIT script. – drummingrocks Oct 31 '17 at 11:41
  • It should work. You might be missing something. Make sure you have followed all the steps mentioned here under second approach http://learn-automation.com/handle-windows-authentication-using-selenium-webdriver/ – Shoaib Akhtar Oct 31 '17 at 12:14
  • I got it to successfully launch with this: var child_process = require('child_process'); var workerProcess = child_process.execFile("C:\\Selenium\\script.exe"); – drummingrocks Oct 31 '17 at 15:06
  • You should post that as an answer and accept it so that other can benefit from it – Shoaib Akhtar Nov 01 '17 at 05:03
  • Thanks--will do. Thank you for all of your help! – drummingrocks Nov 01 '17 at 12:56
0

You can also directly insert the username and password into the Url.

Example: http://username:password@yourUrl.com

So in code you can say (in c#)

string yourUrl = "http://"+username+":"+password+"@yourUrl.com";
driver.Url = yourUrl;

Or java

String yourUrl = "http://"+username+":"+password+"@yourUrl.com";
driver.get(yourUrl);
Anand
  • 1,899
  • 1
  • 13
  • 23
0

I ended up using AutoIT and writing a simple script for it to handle the login window. This was what I used:

Send("{TAB}{ENTER}")
Sleep(2000)
Send("user{TAB}password{ENTER}")

I called the AutoIT script within Selenium with this Javascript function:

function autoIT() {
    var child_process = require('child_process');
    var workerProcess = child_process.execFile("C:\\Selenium\\autoitscript.exe");
    sleep(4500).then(() => {
siteNavigate();
});

After the AutoIT script runs, you can then move back to using Selenium.