Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion Sources/SwiftWebDriver/API/Request/Elements/ElementsTypes.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ElementsTypes.swift
// Copyright (c) 2025 GetAutomaApp
// Copyright (c) 2026 GetAutomaApp
// All source code and related assets are the property of GetAutomaApp.
// All rights reserved.

Expand All @@ -17,19 +17,43 @@
/// The **Enter** key (Unicode: `\u{E007}`).
///
/// Typically used to submit forms or trigger button actions in web pages.
case ENTER1 = "\u{E007}"

Check warning on line 20 in Sources/SwiftWebDriver/API/Request/Elements/ElementsTypes.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Enum cases should be sorted (sorted_enum_cases)

/// The **Return** key (Unicode: `\u{E006}`).
///
/// Often treated similarly to `Enter`, but provided as a separate code
/// for systems that distinguish between them.
case RETURN1 = "\u{E006}"

Check warning on line 26 in Sources/SwiftWebDriver/API/Request/Elements/ElementsTypes.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Enum cases should be sorted (sorted_enum_cases)

/// The **Tab** key (Unicode: `\u{E004}`).
///
/// Used to move focus between interactive elements (e.g., form fields) in a web page.
case TAB = "\u{E004}"

Check warning on line 31 in Sources/SwiftWebDriver/API/Request/Elements/ElementsTypes.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Enum cases should be sorted (sorted_enum_cases)

case NULL = "\u{E000}"

Check warning on line 33 in Sources/SwiftWebDriver/API/Request/Elements/ElementsTypes.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Enum cases should be sorted (sorted_enum_cases)
case CANCEL = "\u{E001}"

Check warning on line 34 in Sources/SwiftWebDriver/API/Request/Elements/ElementsTypes.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Enum cases should be sorted (sorted_enum_cases)
case HELP = "\u{E002}"

Check warning on line 35 in Sources/SwiftWebDriver/API/Request/Elements/ElementsTypes.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Enum cases should be sorted (sorted_enum_cases)
case BACKSPACE = "\u{E003}"

Check warning on line 36 in Sources/SwiftWebDriver/API/Request/Elements/ElementsTypes.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Enum cases should be sorted (sorted_enum_cases)
case CLEAR = "\u{E005}"

Check warning on line 37 in Sources/SwiftWebDriver/API/Request/Elements/ElementsTypes.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Enum cases should be sorted (sorted_enum_cases)
case SHIFT = "\u{E008}"

Check warning on line 38 in Sources/SwiftWebDriver/API/Request/Elements/ElementsTypes.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Enum cases should be sorted (sorted_enum_cases)
case CONTROL = "\u{E009}"
case ALT = "\u{E00A}"
case PAUSE = "\u{E00B}"
case ESCAPE = "\u{E00C}"
case SPACE = "\u{E00D}"
case PAGE_UP = "\u{E00E}"

Check failure on line 44 in Sources/SwiftWebDriver/API/Request/Elements/ElementsTypes.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Enum element name 'PAGE_UP' should only contain alphanumeric and other allowed characters (identifier_name)
case PAGE_DOWN = "\u{E00F}"

Check failure on line 45 in Sources/SwiftWebDriver/API/Request/Elements/ElementsTypes.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Enum element name 'PAGE_DOWN' should only contain alphanumeric and other allowed characters (identifier_name)
case END = "\u{E010}"
case HOME = "\u{E011}"
case LEFT_ARROW = "\u{E012}"

Check failure on line 48 in Sources/SwiftWebDriver/API/Request/Elements/ElementsTypes.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Enum element name 'LEFT_ARROW' should only contain alphanumeric and other allowed characters (identifier_name)
case UP_ARROW = "\u{E013}"

Check failure on line 49 in Sources/SwiftWebDriver/API/Request/Elements/ElementsTypes.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Enum element name 'UP_ARROW' should only contain alphanumeric and other allowed characters (identifier_name)
case RIGHT_ARROW = "\u{E014}"

Check failure on line 50 in Sources/SwiftWebDriver/API/Request/Elements/ElementsTypes.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Enum element name 'RIGHT_ARROW' should only contain alphanumeric and other allowed characters (identifier_name)
case DOWN_ARROW = "\u{E015}"

Check failure on line 51 in Sources/SwiftWebDriver/API/Request/Elements/ElementsTypes.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Enum element name 'DOWN_ARROW' should only contain alphanumeric and other allowed characters (identifier_name)
case INSERT = "\u{E016}"
case DELETE = "\u{E017}"
case F1 = "\u{E031}"

Check failure on line 54 in Sources/SwiftWebDriver/API/Request/Elements/ElementsTypes.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Enum element name 'F1' should be between 3 and 40 characters long (identifier_name)
case F2 = "\u{E032}"

Check failure on line 55 in Sources/SwiftWebDriver/API/Request/Elements/ElementsTypes.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Enum element name 'F2' should be between 3 and 40 characters long (identifier_name)

/// The raw Unicode representation of the key.
///
/// This string value is what will be sent to the WebDriver `sendKeys`
Expand Down
19 changes: 18 additions & 1 deletion Sources/SwiftWebDriver/Element/Element.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Element.swift
// Copyright (c) 2025 GetAutomaApp
// Copyright (c) 2026 GetAutomaApp
// All source code and related assets are the property of GetAutomaApp.
// All rights reserved.

Expand Down Expand Up @@ -264,6 +264,23 @@ public struct Element: ElementCommandProtocol, Sendable {
return response.value
}

@discardableResult
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
public func sendKeys(
keys: ElementsTypes.SendValueActionKeyTypes...,
characters: String = ""
) async throws -> String? {
let text = keys.map(\.rawValue).joined() + characters
let request = PostElementSendValueRequest(
baseURL: baseURL,
sessionId: sessionId,
elementId: elementId,
text: text
)
let response = try await APIClient.shared.request(request)
return response.value
}

/// Takes a screenshot of the element.
///
/// - Returns: A Base64-encoded string representing the image.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ChromeDriverElementHandleIntegrationTests.swift
// Copyright (c) 2025 GetAutomaApp
// Copyright (c) 2026 GetAutomaApp
// All source code and related assets are the property of GetAutomaApp.
// All rights reserved.

Expand Down Expand Up @@ -95,6 +95,22 @@ internal class ChromeDriverElementHandleIntegrationTests: ChromeDriverTest {
#expect(text == "newValue")
}

@Test("Send Chord")
public func sendChord() async throws {
page = "elementHandleTestPage.html"
try await driver.navigateTo(urlString: testPageURL.absoluteString)
let element = try await driver.findElement(.css(.id("sendValue")))
try await element.send(value: "newValue")
let text = try await driver.execute("return document.querySelector('#sendValue').value").value?.stringValue
#expect(text == "newValue")

// Remove text from element
try await element.sendKeys(keys: .CONTROL, characters: "a")
try await element.sendKeys(keys: .BACKSPACE)
let newText = try await driver.execute("return document.querySelector('#sendValue').value").value?.stringValue
#expect(newText == "")
}

@Test("Get Screenshot")
public func getScreenshot() async throws {
page = "elementHandleTestPage.html"
Expand Down
Loading