Skip to content
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

action "send_keys added" #3

Merged
merged 1 commit into from
Aug 30, 2023
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
4 changes: 4 additions & 0 deletions docs/data-sources/recipe.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ Supported actions:
- **set_value**: sets value of form, input, textarea or any other element with a ".value" field.

> ["set_value", "#example-After textarea", "text"]. "text" will be set in the text area.

- **send_keys**: synthesizes the key up, char, and down events.

> ["send_keys", "#example-After textarea", "text"] - types "text" in textarea

- **text**: retrieves the visible text of the first element node matching the selector. Last argument places caught value into "values" attribute under specified key

Expand Down
7 changes: 7 additions & 0 deletions internal/provider/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ func actionBuilder(actionArgs []types.String) (*Action, error) {
}
selector := args[0].ValueString()
dpAction = chromedp.SendKeys(selector, kb.Enter)
case "send_keys":
if len(args) != 2 {
return nil, fmt.Errorf("send_keys action expects 2 arguments (selector and value), got %d: %v", len(args), args)
}
selector := args[0].ValueString()
value := args[1].ValueString()
dpAction = chromedp.SendKeys(selector, value)
default:
return nil, fmt.Errorf("unknown action: %s", verb)
}
Expand Down
4 changes: 4 additions & 0 deletions internal/provider/data_recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ Supported actions:
- **set_value**: sets value of form, input, textarea or any other element with a ".value" field.

> ["set_value", "#example-After textarea", "text"]. "text" will be set in the text area.

- **send_keys**: synthesizes the key up, char, and down events.

> ["send_keys", "#example-After textarea", "text"] - types "text" in textarea

- **text**: retrieves the visible text of the first element node matching the selector. Last argument places caught value into "values" attribute under specified key

Expand Down
3 changes: 2 additions & 1 deletion internal/provider/data_recipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ data "chromedp_recipe" "test" {
["click", "#example-After div.Documentation-exampleButtonsContainer button.Documentation-exampleRunButton"],
["sleep", "3s"],
["text", "#example-After div.Documentation-exampleDetailsBody pre span.Documentation-exampleOutput", "runtext"],
["set_value", "#example-After div.Documentation-exampleDetailsBody textarea", local.hehe_program],
["set_value", "#example-After div.Documentation-exampleDetailsBody textarea", ""], # clear textarea
["send_keys", "#example-After div.Documentation-exampleDetailsBody textarea", local.hehe_program], # type our hee program
["click", "#example-After div.Documentation-exampleButtonsContainer button.Documentation-exampleRunButton"],
["sleep", "3s"],
["text", "#example-After div.Documentation-exampleDetailsBody pre span.Documentation-exampleOutput", "runtext2"],
Expand Down
Loading