Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access popup login form with Selenium in Python

I have been trying for a while to figure out how to enter username and password in the popup-window in this exercise:

http://pentesteracademylab.appspot.com//lab/webapp/digest

but I am entirely new to Selenium in Python. I found out how to click the button, so that the login form pops up:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://pentesteracademylab.appspot.com//lab/webapp/digest")
driver.find_element_by_css_selector('button').click()

but I cannot figure out how to access that window, let alone the fields in it. I have read about switch_to_frame and switch_to_window. For windows there is the window_handles showing you active windows to switch to, but this only returns a single element, which I believe is the main window, not the pop up. I also tried

alert = driver.switch_to_alert()

to no avail. The problem is that I do not know either which kind of object the popup is (frame,window,alert or something else), and I cannot find any names referring to it in the HTML code for the webpage.

Can anyone take me a step further?

like image 756
String Avatar asked Apr 08 '15 13:04

String


People also ask

How does Selenium handle login pop up?

To handle the basic authentication popup, we can pass the username and password along with the web page's URL. When the login pop-up is prompted, we enter the username as “admin” and the password as “admin” and then login. Thus, the user would be successfully logged into the website.

Can Selenium handle window pop-ups?

Yes, it is possible to handle Windows based pop-ups in Selenium webdriver. Sometimes on clicking a link or a button, another window gets opened. It can be a pop up with information or an advertisement. The methods getWindowHandles and getWindowHandle are used to handle child windows.


1 Answers

Pass the authentication step by accessing the following URL:

http://username:[email protected]/lab/webapp/digest/1

See also:

  • Handling browser level authentication using Selenium
like image 178
alecxe Avatar answered Sep 20 '22 15:09

alecxe