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

[CssSelector] Support has CSS selector #53162

Open
janopae opened this issue Dec 20, 2023 · 2 comments
Open

[CssSelector] Support has CSS selector #53162

janopae opened this issue Dec 20, 2023 · 2 comments

Comments

@janopae
Copy link

janopae commented Dec 20, 2023

Description

The has CSS selecter selects the parent of an element that complies to a certain CSS selector. This would be incredibly useful for tests.

https://developer.mozilla.org/en-US/docs/Web/CSS/:has

Example

$tableRowContainingEntity = $table->filter("tr:has(td:contains(\"{$entity->geTitle()}\"))");
self::assertNotEmpty($tableRowContainingEntity);

$secondCell = $tableRowContainingEntity->filter(':nth-child(1)');
self::assertEquals($entity->getDescription(), $secondCell->text());
@xabbuh
Copy link
Member

xabbuh commented Dec 20, 2023

FYI, there is a pending pull request: #49388

@janopae
Copy link
Author

janopae commented Dec 21, 2023

@xabbuh Thanks for pointing this out! I didn't find it.

For the mean time (until it's merged): I just realised that the Crawler allows you to get a node's parent with ->ancestors()->first(). So at least for the case that I provided as an example, it is a workaround to select the child with the CSS selector and then get the parent with the craweler.

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

No branches or pull requests

3 participants