Skip to content

Using the keyboard to input continuously results in missing some content. #1212

@zhuy1228

Description

@zhuy1228

Here is my code, I input a phone number, but the final result is not very good.

package main

import (
	"log"
	"time"

	"github.com/go-rod/rod"
	"github.com/go-rod/rod/lib/input"
	"github.com/go-rod/rod/lib/launcher"
)

func main() {
	url := launcher.New().Headless(false).MustLaunch()
	browser := rod.New().ControlURL(url).MustConnect()
	page := browser.MustPage()
	page.MustNavigate("https://www.google.com").MustWaitLoad()
	page.MustWaitLoad()
	mobildInput := page.Timeout(5 * time.Second).MustElement(`textarea`)
	mobildInput.MustClick()
	mobildInput.MustFocus()
	phone := "+212635413216"
	for _, v := range phone {
		time.Sleep(1 * time.Second)
		log.Println(getKey(string(v)))
		// page.KeyActions().Type(getKey(string(v))).MustDo()
		mobildInput.MustKeyActions().Type(getKey(string(v))).MustDo()
	}
	select {}
}

func getKey(id string) input.Key {
	keys := map[string]input.Key{
		"0": input.Numpad0,
		"1": input.Numpad1,
		"2": input.Numpad2,
		"3": input.Numpad3,
		"4": input.Numpad4,
		"5": input.Numpad5,
		"6": input.Numpad6,
		"7": input.Numpad7,
		"8": input.Numpad8,
		"9": input.Numpad9,
		"+": input.NumpadAdd,
	}
	return keys[id]
}

The final input result is +353

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionQuestions related to rod

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions