@@ -29,8 +29,11 @@ methods to locate elements in a page:
29
29
30
30
31
31
Apart from the public methods given above, there are two private
32
- methods which might be useful with locators in page objects. These
33
- are the two private methods: `find_element ` and `find_elements `.
32
+ methods which might be useful for locating page elements:
33
+
34
+ - `find_element `
35
+ - `find_elements `
36
+
34
37
35
38
Example usage::
36
39
@@ -55,10 +58,10 @@ These are the attributes available for `By` class::
55
58
Locating by Id
56
59
~~~~~~~~~~~~~~
57
60
58
- Use this when you know `id ` attribute of an element. With this
59
- strategy, the first element with the `id ` attribute value matching the
60
- location will be returned. If no element has a matching `id `
61
- attribute, a ``NoSuchElementException `` will be raised.
61
+ Use this when you know the `id ` attribute of an element. With this
62
+ strategy, the first element with a matching `id ` attribute will
63
+ be returned. If no element has a matching `id ` attribute,
64
+ a ``NoSuchElementException `` will be raised.
62
65
63
66
For instance, consider this page source::
64
67
@@ -80,10 +83,10 @@ The form element can be located like this::
80
83
Locating by Name
81
84
~~~~~~~~~~~~~~~~
82
85
83
- Use this when you know `name ` attribute of an element. With this
84
- strategy, the first element with the `name ` attribute value matching
85
- the location will be returned. If no element has a matching `name `
86
- attribute, a ``NoSuchElementException `` will be raised.
86
+ Use this when you know the `name ` attribute of an element. With this
87
+ strategy, the first element with a matching `name ` attribute will
88
+ be returned. If no element has a matching `name ` attribute,
89
+ a ``NoSuchElementException `` will be raised.
87
90
88
91
For instance, consider this page source::
89
92
@@ -115,8 +118,8 @@ Locating by XPath
115
118
XPath is the language used for locating nodes in an XML document. As
116
119
HTML can be an implementation of XML (XHTML), Selenium users can
117
120
leverage this powerful language to target elements in their web
118
- applications. XPath extends beyond (as well as supporting) the simple
119
- methods of locating by id or name attributes, and opens up all sorts
121
+ applications. XPath supports the simple methods of locating by
122
+ id or name attributes and extends them by opening up all sorts
120
123
of new possibilities such as locating the third checkbox on the page.
121
124
122
125
One of the main reasons for using XPath is when you don't have a
@@ -157,34 +160,30 @@ The form elements can be located like this::
157
160
158
161
2. First form element in the HTML
159
162
160
- 3. The form element with attribute named `id ` and the value `loginForm `
163
+ 3. The form element with attribute `id ` set to `loginForm `
161
164
162
165
The username element can be located like this::
163
166
164
167
username = driver.find_element_by_xpath("//form[input/@name='username']")
165
168
username = driver.find_element_by_xpath("//form[@id='loginForm']/input[1]")
166
169
username = driver.find_element_by_xpath("//input[@name='username']")
167
170
168
- 1. First form element with an input child element with attribute named
169
- `name ` and the value `username `
171
+ 1. First form element with an input child element with `name ` set to `username `
170
172
171
- 2. First input child element of the form element with attribute named
172
- `id ` and the value `loginForm `
173
+ 2. First input child element of the form element with attribute `id ` set to `loginForm `
173
174
174
- 3. First input element with attribute named 'name' and the value
175
- `username `
175
+ 3. First input element with attribute `name ` set to `username `
176
176
177
177
The "Clear" button element can be located like this::
178
178
179
179
clear_button = driver.find_element_by_xpath("//input[@name='continue'][@type='button']")
180
180
clear_button = driver.find_element_by_xpath("//form[@id='loginForm']/input[4]")
181
181
182
182
183
- 1. Input with attribute named `name ` and the value `continue ` and
184
- attribute named `type ` and the value `button `
183
+ 1. Input with attribute `name ` set to `continue ` and
184
+ attribute `type ` set to `button `
185
185
186
- 2. Fourth input child element of the form element with attribute named
187
- `id ` and value `loginForm `
186
+ 2. Fourth input child element of the form element with attribute `id ` set to `loginForm `
188
187
189
188
These examples cover some basics, but in order to learn more, the
190
189
following references are recommended:
@@ -212,9 +211,9 @@ discovering the XPath of an element:
212
211
Locating Hyperlinks by Link Text
213
212
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
214
213
215
- Use this when you know link text used within an anchor tag. With this
216
- strategy, the first element with the link text value matching the
217
- location will be returned. If no element has a matching link text
214
+ Use this when you know the link text used within an anchor tag. With this
215
+ strategy, the first element with the link text matching the provided value
216
+ will be returned. If no element has a matching link text
218
217
attribute, a ``NoSuchElementException `` will be raised.
219
218
220
219
For instance, consider this page source::
@@ -258,9 +257,9 @@ The heading (h1) element can be located like this::
258
257
Locating Elements by Class Name
259
258
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
260
259
261
- Use this when you want to locate an element by class attribute name.
262
- With this strategy, the first element with the matching class attribute
263
- name will be returned. If no element has a matching class attribute name,
260
+ Use this when you want to locate an element by class name.
261
+ With this strategy, the first element with the matching class name
262
+ attribute will be returned. If no element has a matching class name attribute ,
264
263
a ``NoSuchElementException `` will be raised.
265
264
266
265
For instance, consider this page source::
@@ -278,9 +277,9 @@ The "p" element can be located like this::
278
277
Locating Elements by CSS Selectors
279
278
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
280
279
281
- Use this when you want to locate an element by CSS selector syntax.
282
- With this strategy, the first element with the matching CSS selector
283
- will be returned. If no element has a matching CSS selector,
280
+ Use this when you want to locate an element using CSS selector syntax.
281
+ With this strategy, the first element matching the given CSS selector
282
+ will be returned. If no element matches the provided CSS selector,
284
283
a ``NoSuchElementException `` will be raised.
285
284
286
285
For instance, consider this page source::
0 commit comments