Skip to content

Allow named selector to not do partial matching #880

Description

@andriokha

Hi, thanks for all the work over the years on this! ❤️

I searched and couldn't find a matching issue (tho #872 covers the same area of the codebase). I'd love to be able to choose to have strict matching when using the named selector (ie named behaves identically to named_exact). It seems currently that the behavior's hardcoded:

public function findAll(string $selector, $locator, string $parentXpath)
{
if ('named' === $selector) {
$items = $this->findAll('named_exact', $locator, $parentXpath);
if (empty($items)) {
$items = $this->findAll('named_partial', $locator, $parentXpath);
}
return $items;
}

And the element finder's instantiated directly in the session constructor:

Mink/src/Session.php

Lines 42 to 50 in 9b08f62

public function __construct(DriverInterface $driver, ?SelectorsHandler $selectorsHandler = null)
{
$this->driver = $driver;
$this->selectorsHandler = $selectorsHandler ?? new SelectorsHandler();
$this->elementFinder = new ElementFinder($driver, $this->selectorsHandler);
$this->page = new DocumentElement($this);
$driver->setSession($this);
}

From my perspective it'd be great to either have a way to override the element finder with my own custom class, or to update the default Mink finder to support switching off fallback partial matching.

Do either of those approaches sound like something you'd consider? If not, is there maybe some other solution?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions