-
Notifications
You must be signed in to change notification settings - Fork 289
Expand file tree
/
Copy pathElementFinder.php
More file actions
70 lines (59 loc) · 1.76 KB
/
Copy pathElementFinder.php
File metadata and controls
70 lines (59 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/*
* This file is part of the Mink package.
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Behat\Mink\Element;
use Behat\Mink\Driver\DriverInterface;
use Behat\Mink\Selector\SelectorsHandler;
use Behat\Mink\Selector\Xpath\Manipulator;
/**
* @final
* @internal
*/
class ElementFinder
{
/**
* @var DriverInterface
*/
private $driver;
/**
* @var SelectorsHandler
*/
private $selectorsHandler;
/**
* @var Manipulator
*/
private $xpathManipulator;
public function __construct(DriverInterface $driver, SelectorsHandler $selectorsHandler, ?Manipulator $xpathManipulator = null)
{
$this->driver = $driver;
$this->selectorsHandler = $selectorsHandler;
$this->xpathManipulator = $xpathManipulator ?? new Manipulator();
}
/**
* @param string|array $locator
*
* @return list<NodeElement>
*/
public function findAll(string $selector, $locator, string $parentXpath): array
{
if ('named' === $selector) {
$items = $this->findAll('named_exact', $locator, $parentXpath);
if (empty($items)) {
$items = $this->findAll('named_partial', $locator, $parentXpath);
}
return $items;
}
$xpath = $this->selectorsHandler->selectorToXpath($selector, $locator);
$xpath = $this->xpathManipulator->prepend($xpath, $parentXpath);
$elements = array();
foreach ($this->driver->find($xpath) as $elementXpath) {
$elements[] = new NodeElement($elementXpath, $this->driver, $this);
}
return $elements;
}
}