RemoteWebElement::findElements()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 11
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 18
rs 9.9
1
<?php
2
3
namespace Bavix\Cases;
4
5
use Facebook\WebDriver\Remote\DriverCommand;
6
use Facebook\WebDriver\WebDriverBy;
7
8
class RemoteWebElement extends \Facebook\WebDriver\Remote\RemoteWebElement
9
{
10
11
    /**
12
     * Find the first WebDriverElement within this element using the given mechanism.
13
     *
14
     * @param WebDriverBy $by
15
     * @return RemoteWebElement NoSuchElementException is thrown in
16
     *    HttpCommandExecutor if no element is found.
17
     * @see WebDriverBy
18
     */
19
    public function findElement(WebDriverBy $by)
20
    {
21
        $params = [
22
            'using' => $by->getMechanism(),
23
            'value' => $by->getValue(),
24
            ':id' => $this->id,
25
        ];
26
        $raw_element = $this->executor->execute(
27
            DriverCommand::FIND_CHILD_ELEMENT,
28
            $params
29
        );
30
31
        return $this->newElement(current($raw_element));
32
    }
33
34
    /**
35
     * Find all WebDriverElements within this element using the given mechanism.
36
     *
37
     * @param WebDriverBy $by
38
     * @return RemoteWebElement[] A list of all WebDriverElements, or an empty
39
     *    array if nothing matches
40
     * @see WebDriverBy
41
     */
42
    public function findElements(WebDriverBy $by)
43
    {
44
        $params = [
45
            'using' => $by->getMechanism(),
46
            'value' => $by->getValue(),
47
            ':id' => $this->id,
48
        ];
49
        $raw_elements = $this->executor->execute(
50
            DriverCommand::FIND_CHILD_ELEMENTS,
51
            $params
52
        );
53
54
        $elements = [];
55
        foreach ($raw_elements as $raw_element) {
56
            $elements[] = $this->newElement(current($raw_element));
57
        }
58
59
        return $elements;
60
    }
61
62
}
63