Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/selenium/webdriver/edge/options.py
4011 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
from selenium.webdriver.chromium.options import ChromiumOptions
19
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
20
21
22
class Options(ChromiumOptions):
23
KEY = "ms:edgeOptions"
24
25
def __init__(self) -> None:
26
"""Initialize EdgeOptions with default settings."""
27
super().__init__()
28
self._use_webview = False
29
30
@property
31
def use_webview(self) -> bool:
32
"""Returns Whether WebView2 is enabled for Edge browser."""
33
return self._use_webview
34
35
@use_webview.setter
36
def use_webview(self, value: bool) -> None:
37
"""Enables or disables WebView2 support for Edge browser.
38
39
Args:
40
value: True to enable WebView2 support, False to disable.
41
"""
42
self._use_webview = bool(value)
43
44
def to_capabilities(self) -> dict:
45
"""Creates a capabilities with all the options that have been set.
46
47
Returns:
48
A dictionary with all set options for Edge browser.
49
"""
50
caps = super().to_capabilities()
51
if self._use_webview:
52
caps["browserName"] = "webview2"
53
54
return caps
55
56
@property
57
def default_capabilities(self) -> dict:
58
"""Returns the default capabilities for Edge browser."""
59
return DesiredCapabilities.EDGE.copy()
60
61