1<?php
2
3namespace Facebook\WebDriver;
4
5/**
6 * The basic 8 mechanisms supported by webdriver to locate a web element.
7 * ie. 'class name', 'css selector', 'id', 'name', 'link text',
8 *     'partial link text', 'tag name' and 'xpath'.
9 *
10 * @see WebDriver::findElement, WebDriverElement::findElement
11 */
12class WebDriverBy
13{
14    /**
15     * @var string
16     */
17    private $mechanism;
18    /**
19     * @var string
20     */
21    private $value;
22
23    protected function __construct($mechanism, $value)
24    {
25        $this->mechanism = $mechanism;
26        $this->value = $value;
27    }
28
29    /**
30     * @return string
31     */
32    public function getMechanism()
33    {
34        return $this->mechanism;
35    }
36
37    /**
38     * @return string
39     */
40    public function getValue()
41    {
42        return $this->value;
43    }
44
45    /**
46     * Locates elements whose class name contains the search value; compound class
47     * names are not permitted.
48     *
49     * @param string $class_name
50     * @return static
51     */
52    public static function className($class_name)
53    {
54        return new static('class name', $class_name);
55    }
56
57    /**
58     * Locates elements matching a CSS selector.
59     *
60     * @param string $css_selector
61     * @return static
62     */
63    public static function cssSelector($css_selector)
64    {
65        return new static('css selector', $css_selector);
66    }
67
68    /**
69     * Locates elements whose ID attribute matches the search value.
70     *
71     * @param string $id
72     * @return static
73     */
74    public static function id($id)
75    {
76        return new static('id', $id);
77    }
78
79    /**
80     * Locates elements whose NAME attribute matches the search value.
81     *
82     * @param string $name
83     * @return static
84     */
85    public static function name($name)
86    {
87        return new static('name', $name);
88    }
89
90    /**
91     * Locates anchor elements whose visible text matches the search value.
92     *
93     * @param string $link_text
94     * @return static
95     */
96    public static function linkText($link_text)
97    {
98        return new static('link text', $link_text);
99    }
100
101    /**
102     * Locates anchor elements whose visible text partially matches the search
103     * value.
104     *
105     * @param string $partial_link_text
106     * @return static
107     */
108    public static function partialLinkText($partial_link_text)
109    {
110        return new static('partial link text', $partial_link_text);
111    }
112
113    /**
114     * Locates elements whose tag name matches the search value.
115     *
116     * @param string $tag_name
117     * @return static
118     */
119    public static function tagName($tag_name)
120    {
121        return new static('tag name', $tag_name);
122    }
123
124    /**
125     * Locates elements matching an XPath expression.
126     *
127     * @param string $xpath
128     * @return static
129     */
130    public static function xpath($xpath)
131    {
132        return new static('xpath', $xpath);
133    }
134}
135