1 | <?php |
||
10 | abstract class AbstractXPath extends AbstractQuery |
||
11 | { |
||
12 | /** |
||
13 | * Match by id |
||
14 | */ |
||
15 | const ID = "@id = '%s'"; |
||
16 | |||
17 | /** |
||
18 | * Match by name |
||
19 | */ |
||
20 | const NAME = "@name = '%s'"; |
||
21 | |||
22 | /** |
||
23 | * Match by placeholder |
||
24 | */ |
||
25 | const PLACEHOLDER = "@placeholder = '%s'"; |
||
26 | |||
27 | /** |
||
28 | * Match by label pointing to element |
||
29 | */ |
||
30 | const LABEL_FOR = "@id = //label[normalize-space() = '%s']/@for"; |
||
31 | |||
32 | /** |
||
33 | * Match by text of an option tag inside the select |
||
34 | */ |
||
35 | const OPTION_TEXT = "(self::select and ./option[(@value = \"\" or not(@value)) and contains(normalize-space(), \"%s\")])"; |
||
36 | |||
37 | /** |
||
38 | * Match by title |
||
39 | */ |
||
40 | const TITLE = "contains(@title, '%s')"; |
||
41 | |||
42 | /** |
||
43 | * Match by plain text content |
||
44 | */ |
||
45 | const TEXT = "contains(normalize-space(), '%s')"; |
||
46 | |||
47 | /** |
||
48 | * Match by alt of an img tag |
||
49 | */ |
||
50 | const IMG_ALT = "descendant::img[contains(@alt, '%s')]"; |
||
51 | |||
52 | /** |
||
53 | * Match by value of element |
||
54 | */ |
||
55 | const VALUE = "contains(@value, '%s')"; |
||
56 | |||
57 | /** |
||
58 | * @return string |
||
59 | */ |
||
60 | 1 | public function getXPath() |
|
61 | { |
||
62 | $type = $this->getType(); |
||
63 | $combined = join(' or ', $this->getMatchers()); |
||
64 | $filled = str_replace('%s', $this->getSelector(), $combined); |
||
65 | |||
66 | 1 | return "//*[($type) and ($filled)]"; |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * @return string |
||
71 | */ |
||
72 | abstract public function getType(); |
||
73 | |||
74 | /** |
||
75 | * @return array |
||
76 | */ |
||
77 | abstract public function getMatchers(); |
||
78 | } |
||
79 |