Skip to content

[py] Created Method to return Keys.CONTROL or Keys.COMMAND based on User OS #15026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: trunk
Choose a base branch
from
4 changes: 4 additions & 0 deletions py/selenium/webdriver/common/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# under the License.
"""The Keys implementation."""

import sys


class Keys:
"""Set of special keys codes."""
Expand Down Expand Up @@ -88,3 +90,5 @@ class Keys:
META = "\ue03d"
COMMAND = "\ue03d"
ZENKAKU_HANKAKU = "\ue040"

COMMAND_OR_CONTROL = COMMAND if sys.platform == "darwin" else CONTROL
10 changes: 10 additions & 0 deletions py/test/selenium/webdriver/common/typing_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,13 @@ def test_should_type_an_integer(driver, pages):
element = driver.find_element(by=By.ID, value="keyReporter")
element.send_keys(1234)
assert element.get_attribute("value") == "1234"


def test_should_type_ctrl_or_command_based_on_os(driver, pages):
pages.load("javascriptPage.html")
element = driver.find_element(by=By.ID, value="keyReporter")
element.send_keys(1234)
assert element.get_attribute("value") == "1234"
element.send_keys(Keys.COMMAND_OR_CONTROL + "a")
element.send_keys(Keys.BACKSPACE)
assert element.get_attribute("value") == ""
Loading