Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/selenium/webdriver/remote/fedcm.py
3985 views
1
# Licensed to the Software Freedom Conservancy (SFC) under one
2
# or more contributor license agreements. See the NOTICE file
3
# distributed with this work for additional information
4
# regarding copyright ownership. The SFC licenses this file
5
# to you under the Apache License, Version 2.0 (the
6
# "License"); you may not use this file except in compliance
7
# with the License. You may obtain a copy of the License at
8
#
9
# http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing,
12
# software distributed under the License is distributed on an
13
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
# KIND, either express or implied. See the License for the
15
# specific language governing permissions and limitations
16
# under the License.
17
18
19
from selenium.webdriver.remote.command import Command
20
21
22
class FedCM:
23
def __init__(self, driver) -> None:
24
self._driver = driver
25
26
@property
27
def title(self) -> str:
28
"""Gets the title of the dialog."""
29
return self._driver.execute(Command.GET_FEDCM_TITLE)["value"].get("title")
30
31
@property
32
def subtitle(self) -> str | None:
33
"""Gets the subtitle of the dialog."""
34
return self._driver.execute(Command.GET_FEDCM_TITLE)["value"].get("subtitle")
35
36
@property
37
def dialog_type(self) -> str:
38
"""Gets the type of the dialog currently being shown."""
39
return self._driver.execute(Command.GET_FEDCM_DIALOG_TYPE).get("value")
40
41
@property
42
def account_list(self) -> list[dict]:
43
"""Gets the list of accounts shown in the dialog."""
44
return self._driver.execute(Command.GET_FEDCM_ACCOUNT_LIST).get("value")
45
46
def select_account(self, index: int) -> None:
47
"""Selects an account from the dialog by index."""
48
self._driver.execute(Command.SELECT_FEDCM_ACCOUNT, {"accountIndex": index})
49
50
def accept(self) -> None:
51
"""Clicks the continue button in the dialog."""
52
self._driver.execute(Command.CLICK_FEDCM_DIALOG_BUTTON, {"dialogButton": "ConfirmIdpLoginContinue"})
53
54
def dismiss(self) -> None:
55
"""Cancels/dismisses the FedCM dialog."""
56
self._driver.execute(Command.CANCEL_FEDCM_DIALOG)
57
58
def enable_delay(self) -> None:
59
"""Re-enables the promise rejection delay for FedCM."""
60
self._driver.execute(Command.SET_FEDCM_DELAY, {"enabled": True})
61
62
def disable_delay(self) -> None:
63
"""Disables the promise rejection delay for FedCM."""
64
self._driver.execute(Command.SET_FEDCM_DELAY, {"enabled": False})
65
66
def reset_cooldown(self) -> None:
67
"""Resets the FedCM dialog cooldown, allowing immediate retriggers."""
68
self._driver.execute(Command.RESET_FEDCM_COOLDOWN)
69
70