GithubHelp home page GithubHelp logo

How to drag with rod? about rod HOT 14 CLOSED

NormalPunch avatar NormalPunch commented on July 19, 2024
How to drag with rod?

from rod.

Comments (14)

ysmood avatar ysmood commented on July 19, 2024 1

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("")
}

from rod.

NormalPunch avatar NormalPunch commented on July 19, 2024

I thought Swipe = Down - Moves - Up , but looked into rod a little, really couldn't move, Down - Moves - Up was more like Click...

But Move worked fine when used alone...I mean, without holding the InputMouseButtonLeft

from rod.

NormalPunch avatar NormalPunch commented on July 19, 2024

Chrome: 83

from rod.

ysmood avatar ysmood commented on July 19, 2024

Sorry, this is a known issue:

https://github.com/ysmood/rod/blob/efd99d27e081c6a62603153074a46c3f01759233/page_test.go#L293-L304

from rod.

ysmood avatar ysmood commented on July 19, 2024

I still don't know why it doesn't work. Feels like a bug of Chrome

from rod.

ysmood avatar ysmood commented on July 19, 2024

If you look at the puppeteer.js, they have the same issue:

puppeteer/puppeteer#4562

puppeteer/puppeteer#1376

from rod.

NormalPunch avatar NormalPunch commented on July 19, 2024

I still don't know why it doesn't work. Feels like a bug of Chrome

Shocked at this fact...

from rod.

ysmood avatar ysmood commented on July 19, 2024

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.

from rod.

ysmood avatar ysmood commented on July 19, 2024

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

from rod.

NormalPunch avatar NormalPunch commented on July 19, 2024

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.

Thanks @ysmood , but it was still stucked. 😥

from rod.

NormalPunch avatar NormalPunch commented on July 19, 2024

Ok, I get it now, thanks @ysmood !

from rod.

ysmood avatar ysmood commented on July 19, 2024

The latest chrome has fixed this issue, now it works for both headless and headful.

from rod.

heemike avatar heemike commented on July 19, 2024

page.Element("#pager").Box() ,出现错误,没有这个方法Box()。

from rod.

ysmood avatar ysmood commented on July 19, 2024

The code is outdated, check the new doc:

rod/input_test.go

Lines 184 to 197 in b7f9c86

func TestMouseDrag(t *testing.T) {
g := setup(t)
page := g.newPage().MustNavigate(g.srcFile("fixtures/drag.html")).MustWaitLoad()
mouse := page.Mouse
mouse.MustMoveTo(3, 3)
mouse.MustDown("left")
g.E(mouse.MoveLinear(proto.NewPoint(60, 80), 3))
mouse.MustUp("left")
utils.Sleep(0.3)
g.Eq(page.MustEval(`() => dragTrack`).Str(), " move 3 3 down 3 3 move 22 28 move 41 54 move 60 80 up 60 80")
}

from rod.

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.