Skip to content

Commit 8925c0f

Browse files
committed
adding Authenticate Alert API to python
1 parent bb1c876 commit 8925c0f

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

py/CHANGES

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Selenium 2.47.0 (in development)
22
* Adding ability to make remote call for webelement screenshots in accordance to the W3C spec
3+
* Adding api to authenticate HTTP Auth modal dialogs via driver.switch_to.alert (beta)
34

45
Selenium 2.46.0
56
* Firefox support up to 38

py/selenium/webdriver/common/alert.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ class Alert(object):
2626
"""
2727
Allows to work with alerts.
2828
29-
Use this class to interact with alert prompts. It contains methods for dismissing,
29+
Use this class to interact with alert prompts. It contains methods for dismissing,
3030
accepting, inputting, and getting text from alert prompts.
3131
3232
Accepting / Dismissing alert prompts::
33-
33+
3434
Alert(driver).accept()
3535
Alert(driver).dismiss()
3636
@@ -86,6 +86,19 @@ def send_keys(self, keysToSend):
8686
:Args:
8787
- keysToSend: The text to be sent to Alert.
8888
89-
89+
9090
"""
9191
self.driver.execute(Command.SET_ALERT_VALUE, {'text': keysToSend})
92+
93+
def authenticate(self, username, password):
94+
"""
95+
Send the username / password to an Authenticated dialog (like with Basic HTTP Auth)
96+
97+
Usage::
98+
driver.switch_to.alert.authenticate('cheese', 'secretGouda')
99+
100+
:Args:
101+
-username: string to be set in the username section of the dialog
102+
-password: string to be set in the password section of the dialog
103+
"""
104+
self.driver.execute(Command.SET_ALERT_AUTHENTICATION, {'username':username, 'password':password})

py/selenium/webdriver/remote/command.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class Command(object):
9797
ACCEPT_ALERT = "acceptAlert"
9898
SET_ALERT_VALUE = "setAlertValue"
9999
GET_ALERT_TEXT = "getAlertText"
100+
SET_ALERT_AUTHENTICATION = "setAuthentication"
100101

101102
# Advanced user interactions
102103
CLICK = "mouseClick"
@@ -142,7 +143,7 @@ class Command(object):
142143
SET_SESSION_STORAGE_ITEM = "setSessionStorageItem"
143144
CLEAR_SESSION_STORAGE = "clearSessionStorage"
144145
GET_SESSION_STORAGE_SIZE = "getSessionStorageSize"
145-
146+
146147
# Mobile
147148
GET_NETWORK_CONNECTION = "getNetworkConnection"
148149
SET_NETWORK_CONNECTION = "setNetworkConnection"

py/selenium/webdriver/remote/remote_connection.py

+2
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ def __init__(self, remote_server_addr, keep_alive=False):
275275
('POST', '/session/$sessionId/alert_text'),
276276
Command.GET_ALERT_TEXT:
277277
('GET', '/session/$sessionId/alert_text'),
278+
Command.SET_ALERT_AUTHENTICATION:
279+
('POST', '/session/$sessionId/authenticate'),
278280
Command.CLICK:
279281
('POST', '/session/$sessionId/click'),
280282
Command.DOUBLE_CLICK:

0 commit comments

Comments
 (0)