Comments (13)
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:
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.
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.
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.
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.
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.
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.
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.
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.
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.
Alright, thanks. I'll start playing with it shortly.
from chromedp.
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.
Awesome, thanks for all the hard work @kenshaw! I look forward to testing it!
from chromedp.
Attaching log for posterity.
cdp-ba7a88bb-fb2f-410a-8a1c-f63fc43f567e.txt
from chromedp.
Related Issues (20)
- Navigate Hangup with custom url scheme HOT 1
- page.StopLoading() cannot stop navigate
- chrome failed to start with no detail error
- Screenshot from remote browser
- context canceled even with new context HOT 1
- Download events being omitted on the page level but chromedp listens for it on the Browser level HOT 1
- Image not showing up in header
- Can't use proxy and open multiple tabs ?
- Target.targetCrashed > errorCode 11 with chromedp.Navigate() in Docker container environnement HOT 7
- Is it possible to use the net/http client in chromedp ? HOT 1
- GetOuterHTML().WithPierce(true) not returning <iframe> contents
- How to execute JavaScript in a specified context? HOT 1
- How to set the state of ShadowDOM from closed to open?
- Question: condition for set FooterTemplate
- Is it possible to capture error messages related to CORS, CSP violations, mixed-content violations, etc.?
- Can I Capture Raw HTTP Data?
- How to start chrome in arm environment?Are there any other plans?
- Why can't I listen to my iframe's network requests
- How i get dpi of chrome
- Import cookie using json
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chromedp.