-
-
Notifications
You must be signed in to change notification settings - Fork 333
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
How to drag with rod? #46
Comments
I thought But |
Chrome: 83 |
Sorry, this is a known issue: https://github.com/ysmood/rod/blob/efd99d27e081c6a62603153074a46c3f01759233/page_test.go#L293-L304 |
I still don't know why it doesn't work. Feels like a bug of Chrome |
If you look at the puppeteer.js, they have the same issue: |
Shocked at this fact... |
But if you use headless mode, it should work as expected. This issue is only for head mode which means you can't watch it on live. This test shows the events will happen correctly: https://github.com/ysmood/rod/blob/f59cc63696ec5beef2bc5ec0541bebd3f50330f1/page_test.go#L293-L315 I think the reason is that in head mode chrome will use the position of your real mouse, not the mocked one. A typical race condition bug which is really hard to resolve (since you still want to interact with the controlled page with the real mouse to debug), that's why this bug is there for so many years. |
You can use the monitor helper to watch what's happening when it runs in the background: https://github.com/ysmood/rod/blob/f59cc63696ec5beef2bc5ec0541bebd3f50330f1/examples_test.go#L69-L70 |
Thanks @ysmood , but it was still stucked. 😥 |
Here's the example, it works on headless mode: func main() {
browser := rod.New().Connect()
defer browser.Close()
pageURL := "your url"
page.Navigate(pageURL)
wait := page.WaitRequestIdle()
wait()
box := page.Element(".slider").Box()
kit.Dump(box)
mouse := page.Mouse
mouse.Move(box.Left, box.Top)
mouse.Down("left")
mouse.MoveE(box.Left+100, box.Top, 5) // drag 100px to the right
page.Screenshot("")
mouse.Up("left")
page.Screenshot("")
} |
Ok, I get it now, thanks @ysmood ! |
The latest chrome has fixed this issue, now it works for both headless and headful. |
|
The code is outdated, check the new doc: Lines 184 to 197 in b7f9c86
|
I tried to solve a drag captcha with rod:
The captcha will be loaded in an iframe, I can click buttons in the iframe but cannot drag.
It seemed that only the
Down
andUp
success, but theMove
do nothing with no error.Any idea? Thanks!
The text was updated successfully, but these errors were encountered: