Git Product home page Git Product logo

Comments (13)

JohnStarich avatar JohnStarich commented on May 18, 2024 6

Sorry for reviving an old issue, this issue showed up as a top result in my search. I ran into this problem on a simple dropdown and had trouble getting arrow keys to actually update the option.

My page's dropdown wrapped a normal browser dropdown's styles, but ignored arrow key presses after it opened like this:

image

For anyone landing here in search of an easy dropdown solution, I selected the correct option with this:

chromedp.SendKeys(`#mydropdown`, "Text label content")

This focused on the select element and typed out the label. Typing the label chooses the right option and fires off the required events for a JS dropdown.

from chromedp.

kenshaw avatar kenshaw commented on May 18, 2024 1

Also, typically my experience with chromedp, selenium, and other libraries that do similiar things, it's typically easier to call the javascript on the element instead of trying to send key presses. Keep in mind that even option elements can take click events! I also learned a bit more about how chrome works this morning, and will be revamping a bit of the way the query selectors work, so that they traverse frames properly.

from chromedp.

kenshaw avatar kenshaw commented on May 18, 2024 1

Please check the updated examples/keys -- it correctly should be sending the kb.ArrowDown values. Additionally, the other navigation keys (Home/End/etc) should be working "as expected" now.

from chromedp.

clanstyles avatar clanstyles commented on May 18, 2024

Here's a few things I've tried.

		cdp.SendKeys(`//div[@role='listbox']`, ""),
		cdp.ActionFunc(func(ctx context.Context, h cdptypes.FrameHandler) error {
			for a := 0; a < 6; a++ {
				if err := input.DispatchKeyEvent(input.KeyDown).Do(ctx, h); err != nil {
					return err
				}
			}
			return nil
		}),

`

from chromedp.

kenshaw avatar kenshaw commented on May 18, 2024

For system keys, you need to send the raw key event as well. Look at the current SendKeys implementation.

That said, I think a "KeyDown" and "KeyUp" generic actions would be good, and I'll add that to the code shortly.

from chromedp.

kenshaw avatar kenshaw commented on May 18, 2024

BTW -- the input event type "keyDown" for Chrome refers to sending an event equivalent to a physical keyboard's events for "key down" -- it's not the "down arrow" button.

from chromedp.

clanstyles avatar clanstyles commented on May 18, 2024

Depending on the framework, the javascript method is still problematic. There can be data attributes and hidden fields that all need to be updated.

For "keydown" do you mean like 40 (as in the code for the key on the keyboard)?

from chromedp.

kenshaw avatar kenshaw commented on May 18, 2024

Yes. I understand the potential issues, I'm writing a generic way to send the key presses now. It's just a matter of knowing the right codes. What OS are you running this on?

from chromedp.

kenshaw avatar kenshaw commented on May 18, 2024

I just pushed a commit that doesn't really fix this yet, as it doesn't seem to be synthesizing the event. Please see the updated examples/keys/main.go for how I envision the API working.

from chromedp.

clanstyles avatar clanstyles commented on May 18, 2024

Alright, thanks. I'll start playing with it shortly.

from chromedp.

kenshaw avatar kenshaw commented on May 18, 2024

Update: I had figured out the fix for this a couple days ago, but got caught up in fixing other issues. I should be pushing a big commit set either late today or early tomorrow that fixes this properly. For the record, the update should fix key presses for all the regular navigational keys (arrows, home/end/pageup/pagedown) as well as tabs, backspaces, and enter. The API will be the same, just there are special single unicode characters that will correspond to each of those keys.

from chromedp.

clanstyles avatar clanstyles commented on May 18, 2024

Awesome, thanks for all the hard work @kenshaw! I look forward to testing it!

from chromedp.

kenshaw avatar kenshaw commented on May 18, 2024

Attaching log for posterity.
cdp-ba7a88bb-fb2f-410a-8a1c-f63fc43f567e.txt

from chromedp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.