ExpectedCondition::elementRemoved()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 2
eloc 8
nc 1
nop 1
1
<?php
2
3
namespace Magium\WebDriver;
4
5
use Facebook\WebDriver\WebDriverElement;
6
use Facebook\WebDriver\WebDriverExpectedCondition;
7
8
class ExpectedCondition extends WebDriverExpectedCondition
9
{
10
11
    public static function elementExists($selector, $by = 'byId')
12
    {
13
        return new WebDriverExpectedCondition(
14
            function ($driver) use ($selector, $by) {
15
                try {
16
                    $element = $driver->$by($selector);
17
                    return $element instanceof WebDriverElement;
18
                } catch (\Exception $e) {
19
                    // No need to do anything.  No element == exception.
20
                }
21
                return false;
22
            }
23
        );
24
    }
25
26
    public static function elementRemoved(WebDriverElement $element)
27
    {
28
        return new WebDriverExpectedCondition(
29
            function () use ($element) {
30
                try {
31
                    $element->isDisplayed();
32
                    return false;
33
                } catch (\Exception $e) {
34
                    return true;
35
                }
36
            }
37
        );
38
    }
39
40
}