1
  1. How can I handle via a ruby script the basic auth pop up window using gem 'selenium-webdriver', '~> 3.0', or switch and enter a username and password to login pop up/alert window?

  2. Is there a way to edit firefox profile and add to there url and saved logins via the script ?

Also I cant inspect from my browser the elements on the pup up/alert window in order to find the ids.

The the basic auth pop up window not from the URL in @driver.get 'url' in my script, first I go to a different website, then click on some link and I got this basic auth pop-up window. It works when I type manually the user/pass from my browser.

I got exception when I tried to do something like this:

a = @driver.switch_to.alert

a.send_keys("username")

caught exception Missing 'value' parameter!

Screenshot from Chrome-

enter image description here

Screenshot from Firefox-

enter image description here

This way @driver.get 'https://username:password@mysite.com/mypage/' doesn't work so well, its send me back to the login page, and pop up another window:

You are about to log in to the site “launchpad.support.sap.com” with the username “username”, but the website does not require authentication. This may be an attempt to trick you. Is “launchpad.support.sap.com” the site you want to visit?

I found some solutions in java but nothing in ruby :(

Any help would be appreciated,

Thanks!

Berlin
  • 1,456
  • 1
  • 21
  • 43
  • Has selenium started working with firefox again? Last I checked there were some serious conflicts so I just swapped over to using google chrome – MageeWorld Oct 16 '16 at 22:32
  • I looking for solution in ff, also because its the default on ubuntu, and its support headless gem – Berlin Oct 16 '16 at 22:33
  • I understand that - but if you do some research you'll find that selenium and versions of firefox about 47 have a hand shaking problem - they aren't making friends - which could cause the issue. Your error message also indicates that a login isn't required – MageeWorld Oct 16 '16 at 22:35
  • yep, but its send me back to the login page, so you think it is a bug? is there any solution to handle `firefox` popups ? in `chrome` is it appears? also do you know maybe if `chrome` support `headless gem` ? thanks! – Berlin Oct 16 '16 at 22:38
  • I don't know if chrome supports the headless gem but I do know that switching my selenium/rspec combination to use chrome made them work where firefox just failed. It may be a conflict with headless as well - if this is a pop up make sure you are telling your code to switch to the pop up – MageeWorld Oct 16 '16 at 22:41
  • ok thanks, not sure how to write it and handle the auth popup, so I will wait for someone to answer. – Berlin Oct 16 '16 at 22:51
  • I have the same popup on `chrome` – Berlin Oct 16 '16 at 23:41

2 Answers2

0

Syntax may differ since I do it in Python:

from selenium import webdriver

driver = webdriver.Firefox() # or Chrome, works anyways
driver.get('http://user:pass@my.web.page')
try:
    alert = driver.switch_to_alert()
    alert.accept()
except: # be careful, it is very generic example
    log.debug('no alert happened')
user3657041
  • 745
  • 8
  • 9
  • This is the problem, its not the `@driver.get 'url'` from my script, first I go to a different website, then click on some link and I got this basic auth pop-up window. – Berlin Oct 18 '16 at 15:39
  • got it. It appears when you click a link. 1. 3rd-party tool nay help. Like AutoIt: http://learn-automation.com/handle-windows-authentication-using-selenium-webdriver/ check this article, "Second approach" 2. another approach is to use webdriver: http://stackoverflow.com/questions/24304752/how-to-handle-authentication-popup-with-selenium-webdriver-using-java Not sure how it will work with Ruby. I would use AutoIt or similar tool. – user3657041 Oct 18 '16 at 16:13
  • thanks, at the end I need to run it with `headless` , so 3rd-party tool will not be the best for me. I will continue to check but looks like no one knows :( – Berlin Oct 18 '16 at 20:26
0

Interacting with Basic Auth dialogs is "not in scope" with respect to using Selenium/Webdriver (as far as I know). I also agree with this. That said I have to deal with Basic Auth all the time and it is a pain.

Passing the username/password in the URL has been an on-again-off-again thing across browsers. It is a security issue and I think most of today's browsers don't allow it. Last time I checked Chrome re-enabled it but not Firefox.

I use Java, and I'm using AutoIT on Windows nodes in a Selenium Grid. This has worked for us for several years but no longer can "see" the Basic Auth dialog put up by Chrome. Works ok for Firefox and IE8-11.

I tried AppleScript and SokuliX and had some success but both are 'fragile' (especially SokuliX) and limited (AppleScript for macs only). Robot was also tried but it very much like SokuliX, therefore fragile - don't touch the mouse/keyboard when it is in use.

In the end we had to 'whitelist' office environments from being presented with Basic Auth challenges.

kpschmidt
  • 245
  • 3
  • 10
  • thank you, i am not familiar with `java` so much, but I saw someone wrote how to send keys in java [link](http://sqa.stackexchange.com/questions/12892/how-to-send-basic-authentication-headers-in-selenium) – Berlin Oct 18 '16 at 21:36