Skip to content
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

What is "Could not find object with given id" ? #332

Closed
rluisr opened this issue Jan 3, 2021 · 2 comments
Closed

What is "Could not find object with given id" ? #332

rluisr opened this issue Jan 3, 2021 · 2 comments
Labels
question Questions related to rod

Comments

@rluisr
Copy link

rluisr commented Jan 3, 2021

Rod Version: v0.87.2

I want to access the element after logging in to Twitter, but I get an error when I run fmt.Println(page.MustElement("title").MustText()).
I checked a login code is redirected to the user timeline so I think it's working perfectly.

error

[rod] 2021/01/04 01:19:34 [eval] {"js":"rod.element","params":["title"]}
panic: {-32000 Could not find object with given id }

code

func main() {
	l := launcher.New().
		Headless(false).
		Devtools(true)
	defer l.Cleanup()

	url := l.MustLaunch()
	browser := rod.New().
		ControlURL(url).
		Trace(true).
		SlowMotion(1 * time.Second).
		MustConnect()

	launcher.NewBrowser().Open(browser.ServeMonitor(""))
	defer browser.MustClose()

	// Login
	page := browser.MustPage("https://twitter.com/login")

	wait := page.MustWaitRequestIdle("live_pipeline")

	page.MustElement(`[name="session[username_or_email]"]`).MustInput("")
	page.MustElement(`[name="session[password]"]`).MustInput("")
	page.Keyboard.MustPress(input.Enter)

	wait()

	// Output page title after login
	fmt.Println(page.MustElement("title").MustText())

	utils.Pause()
}
@rluisr rluisr added the question Questions related to rod label Jan 3, 2021
@ysmood
Copy link
Member

ysmood commented Jan 3, 2021

If you read the API doc, the rod.Element struct is just a reference id for a remote object in the browser, in your case, it's a remote <title> object:

image

image

The error means the object doesn't exist anymore.

I tried your code, it works fine for me, it will print the title: Login on Twitter / Twitter

@ysmood
Copy link
Member

ysmood commented Jan 3, 2021

If you use an outdated rod.Element it will happen, such as the page uses js to dynamically remove the remote object, or page reloading, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions related to rod
Projects
None yet
Development

No branches or pull requests

2 participants