/
Locator.php
114 lines (103 loc) · 2.51 KB
/
Locator.php
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/*
* This file is part of PHP Selenium Library.
* (c) Alexandre Salomé <alexandre.salome@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Selenium;
/**
* Helping class for locating elements in Selenium.
*
* @author Alexandre Salomé <alexandre.salome@gmail.com>
*/
class Locator
{
/**
* Creates locator with @id or @name attribute.
*
* @param string $idOrName Attribute value
*
* @return string The locator string
*/
public static function IdOrName($idOrName)
{
return 'identifier='.$idOrName;
}
/**
* Creates locator with @id attribute.
*
* @param string $id Attribute value
*
* @return string The locator string
*/
public static function id($id)
{
return 'id='.$id;
}
/**
* Creates locator with @name attribute.
*
* @param string $id Attribute value
* @param string $valuePattern Pattern for the field to locate
* @param int $index Index of the element
*
* @return string The locator string
*/
public static function name($name, $valuePattern = null, $index = null)
{
$result = 'name='.$name;
if (null !== $valuePattern) {
$result .= ' value='.$valuePattern;
}
if (null !== $index) {
$result .= ' index='.$index;
}
return $result;
}
/**
* Creates locator with the Javascript DOM API (document.forms[1] for example).
*
* @param string $expression The DOM expression
*
* @return string The locator string
*/
public static function javascriptDom($expression)
{
return 'dom='.$expression;
}
/**
* Creates locator with XPath selector
*
* @param string $xpath The XPath
*
* @return string The locator string
*/
public static function xpath($xpath)
{
return 'xpath='.$xpath;
}
/**
* Creates locator for a link using a pattern.
*
* @param string $pattern The text pattern
*
* @return string The locator string
*/
public static function linkContaining($pattern)
{
return 'link='.$pattern;
}
/**
* Creates locator with CSS selector
*
* @param string $css The CSS selector
*
* @return string The locator string
*/
public static function css($css)
{
return 'css='.$css;
}
}