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

How does Evaluate work? #459

Open
jonfriesen opened this issue May 24, 2024 · 3 comments
Open

How does Evaluate work? #459

jonfriesen opened this issue May 24, 2024 · 3 comments

Comments

@jonfriesen
Copy link

Hello,

I'm in the progress of migrating some tests to remove uses of the deprecated ElementHandles. Something I've noticed is the following code. Running Evaluate on a Locator times out (except for the rare occasion). Running an Evaluate on an ElementHandle executes immediately.

Can someone help me understand what's going on here and the proper way to call Evaluate on Locators? Sample code below.

// cell is a playwright.Locator
cellHandle, err := cell.ElementHandle()
if err != nil {
	return nil, fmt.Errorf("could not get cell handle: %w", err)
}

// runs immediately and succeeds
handleTagName, err := cellHandle.Evaluate(`e => e.tagName`)
if err != nil {
	return nil, fmt.Errorf("could not get tag: %w", err)
}

// times out
locatorTagName, err := cell.Evaluate(`e => e.tagName`, nil)
if err != nil {
	return nil, fmt.Errorf("could not get tag: %w", err)
}
@canstand
Copy link
Collaborator

The difference between the Locator and ElementHandle is that the latter points to a particular element, while Locator captures the logic of how to retrieve that element.
(https://playwright.dev/docs/release-notes#-new-locators-api)

Maybe when calling locator.Evaluate, the locator cannot find the element that meets the corresponding logic?

@jonfriesen
Copy link
Author

In my case, I'm calling cell.ElementHandle() and the cellHandle.Evaluate(...) functions right next to eachother, just like my example.

Given that cell is the Locator and has to resolve to the ElementHandle, I expected removing that step and calling Evaluate directly on the Locator would resolve the same way, does that sound correct? Or does the Locator cache the ElementHandle?

Thanks for the response :)

@canstand
Copy link
Collaborator

canstand commented Jun 7, 2024

Sorry for the delay. I haven't dug into the details of the upstream implementation, but I don't think Locator caches the ElementHandle.

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

No branches or pull requests

2 participants