python 弹出式网页登录,如何在Python中使用Selenium访问弹出式登录表单

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

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?

解决方案

Pass the authentication step by accessing the following URL:

http://username:password@pentesteracademylab.appspot.com/lab/webapp/digest/1

See also:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值