0

I'm trying to automate my login process to my home router and I want to enter the username and the password into an alert message, unfortunately, I can't do it

after doing some research I found that I can accept the alert using

alert = driver.switch_to.alert alert.accept()

and sending keys into the web using method called send_keys()

but the problem that i have two textboxes instead of one

from selenium import webdriver

driver = webdriver.Chrome()
driver.get("192.168.1.1")

#note i have both textboxes in the same alert
#and the alert popup once I request the page

alert = driver.switch_to.alert

alert.send_keys('admin')
alert.send_keys('admin')
alert.accept()

MrKioZ
  • 515
  • 4
  • 14

2 Answers2

1

I think this is authentication popup. I saw your screenshot now its authentication popup. please use below code and I hope this work for you.

try this :-

driver.get("https://UserName:Password@Example.com")

There are three types of pop-ups you might face.

1)Website pop up, which is basically easy to handle as you can find it’s element locator and sometimes it’s an iframe then you can use the switch to the iframe as well.

2)The second one is browser auth pop up, if your browser has authentication pop up then you don't need to worry about switching, you just need is pass the auth credentials with your URL as https://<username>:<password>@<your-site-name>

3)Third is browser pop up, the browser pop-ups are tricky to handle but if you are seeing the browser pop-ups which is a normal browser pop up then you can use below command to switch into it.

alert_obj = driver.switch_to.alert

For more information read this and this also, Selenium Python Authenticating browser login pupup dialog at a HTTPS website

MrKioZ
  • 515
  • 4
  • 14
Pradnya Bolli
  • 1,915
  • 1
  • 19
  • 37
  • I'm sorry but this solution did not work for me as I'm using Chrome it does not allow me to use this method as I saw in your [Selenium Python Authenticating browser login answer this supports limited browsers but it can work properly on firefox and im using local website which don't have https on it – MrKioZ May 14 '19 at 09:32
  • @bharatk but this make router accessible from through the internet and I don't want to allow this for security – MrKioZ May 14 '19 at 09:47
0

Looks like a bug, Chrome Bug

Try to use FireFox

iAmTryingOK
  • 216
  • 1
  • 10