@@ -49,10 +49,6 @@ public abstract class By {
49
49
* @return A By which locates elements by the value of the "id" attribute.
50
50
*/
51
51
public static By id (final String id ) {
52
- if (id == null )
53
- throw new IllegalArgumentException (
54
- "Cannot find elements when the id is null." );
55
-
56
52
return new ById (id );
57
53
}
58
54
@@ -61,58 +57,38 @@ public static By id(final String id) {
61
57
* @return A By which locates A elements by the exact text they display.
62
58
*/
63
59
public static By linkText (final String linkText ) {
64
- if (linkText == null )
65
- throw new IllegalArgumentException (
66
- "Cannot find elements when the link text is null." );
67
-
68
60
return new ByLinkText (linkText );
69
61
}
70
62
71
63
/**
72
- * @param linkText The text to match against.
73
- * @return A By which locates A elements that contain the given text.
64
+ * @param partialLinkText The partial text to match against
65
+ * @return a By which locates A elements that contain the given link text
74
66
*/
75
- public static By partialLinkText (final String linkText ) {
76
- if (linkText == null )
77
- throw new IllegalArgumentException (
78
- "Cannot find elements when the link text is null." );
79
-
80
- return new ByPartialLinkText (linkText );
67
+ public static By partialLinkText (final String partialLinkText ) {
68
+ return new ByPartialLinkText (partialLinkText );
81
69
}
82
70
83
71
/**
84
72
* @param name The value of the "name" attribute to search for.
85
73
* @return A By which locates elements by the value of the "name" attribute.
86
74
*/
87
75
public static By name (final String name ) {
88
- if (name == null )
89
- throw new IllegalArgumentException (
90
- "Cannot find elements when the name is null." );
91
-
92
76
return new ByName (name );
93
77
}
94
78
95
79
/**
96
- * @param name The element's tag name.
97
- * @return A By which locates elements by their tag name.
80
+ * @param tagName The element's tagName
81
+ * @return a By which locates elements by their tag name
98
82
*/
99
- public static By tagName (final String name ) {
100
- if (name == null )
101
- throw new IllegalArgumentException (
102
- "Cannot find elements when the tag name is null." );
103
-
104
- return new ByTagName (name );
83
+ public static By tagName (final String tagName ) {
84
+ return new ByTagName (tagName );
105
85
}
106
86
107
87
/**
108
88
* @param xpathExpression The XPath to use.
109
89
* @return A By which locates elements via XPath.
110
90
*/
111
91
public static By xpath (final String xpathExpression ) {
112
- if (xpathExpression == null )
113
- throw new IllegalArgumentException (
114
- "Cannot find elements when the XPath is null." );
115
-
116
92
return new ByXPath (xpathExpression );
117
93
}
118
94
@@ -125,10 +101,6 @@ public static By xpath(final String xpathExpression) {
125
101
* @return A By which locates elements by the value of the "class" attribute.
126
102
*/
127
103
public static By className (final String className ) {
128
- if (className == null )
129
- throw new IllegalArgumentException (
130
- "Cannot find elements when the class name is null." );
131
-
132
104
return new ByClassName (className );
133
105
}
134
106
@@ -137,16 +109,11 @@ public static By className(final String className) {
137
109
* implement the Selector API, a best effort is made to emulate the API. In this case, we strive
138
110
* for at least CSS2 support, but offer no guarantees.
139
111
*
140
- * @param selector CSS expression.
112
+ * @param cssSelector CSS expression.
141
113
* @return A By which locates elements by CSS.
142
114
*/
143
- public static By cssSelector (final String selector ) {
144
- if (selector == null )
145
- throw new IllegalArgumentException (
146
- "Cannot find elements when the CSS selector is null." );
147
-
148
- return new ByCssSelector (selector );
149
-
115
+ public static By cssSelector (final String cssSelector ) {
116
+ return new ByCssSelector (cssSelector );
150
117
}
151
118
152
119
/**
@@ -201,6 +168,10 @@ public static class ById extends By implements Serializable {
201
168
private final String id ;
202
169
203
170
public ById (String id ) {
171
+ if (id == null )
172
+ throw new IllegalArgumentException (
173
+ "Cannot find elements with a null id attribute." );
174
+
204
175
this .id = id ;
205
176
}
206
177
@@ -233,6 +204,10 @@ public static class ByLinkText extends By implements Serializable {
233
204
private final String linkText ;
234
205
235
206
public ByLinkText (String linkText ) {
207
+ if (linkText == null )
208
+ throw new IllegalArgumentException (
209
+ "Cannot find elements when link text is null." );
210
+
236
211
this .linkText = linkText ;
237
212
}
238
213
@@ -256,26 +231,30 @@ public static class ByPartialLinkText extends By implements Serializable {
256
231
257
232
private static final long serialVersionUID = 1163955344140679054L ;
258
233
259
- private final String linkText ;
234
+ private final String partialLinkText ;
260
235
261
- public ByPartialLinkText (String linkText ) {
262
- this .linkText = linkText ;
236
+ public ByPartialLinkText (String partialLinkText ) {
237
+ if (partialLinkText == null )
238
+ throw new IllegalArgumentException (
239
+ "Cannot find elements when link text is null." );
240
+
241
+ this .partialLinkText = partialLinkText ;
263
242
}
264
243
265
244
@ Override
266
245
public List <WebElement > findElements (SearchContext context ) {
267
246
return ((FindsByLinkText ) context )
268
- .findElementsByPartialLinkText (linkText );
247
+ .findElementsByPartialLinkText (partialLinkText );
269
248
}
270
249
271
250
@ Override
272
251
public WebElement findElement (SearchContext context ) {
273
- return ((FindsByLinkText ) context ).findElementByPartialLinkText (linkText );
252
+ return ((FindsByLinkText ) context ).findElementByPartialLinkText (partialLinkText );
274
253
}
275
254
276
255
@ Override
277
256
public String toString () {
278
- return "By.partialLinkText: " + linkText ;
257
+ return "By.partialLinkText: " + partialLinkText ;
279
258
}
280
259
}
281
260
@@ -286,6 +265,10 @@ public static class ByName extends By implements Serializable {
286
265
private final String name ;
287
266
288
267
public ByName (String name ) {
268
+ if (name == null )
269
+ throw new IllegalArgumentException (
270
+ "Cannot find elements when name text is null." );
271
+
289
272
this .name = name ;
290
273
}
291
274
@@ -315,29 +298,33 @@ public static class ByTagName extends By implements Serializable {
315
298
316
299
private static final long serialVersionUID = 4699295846984948351L ;
317
300
318
- private final String name ;
301
+ private final String tagName ;
319
302
320
- public ByTagName (String name ) {
321
- this .name = name ;
303
+ public ByTagName (String tagName ) {
304
+ if (tagName == null )
305
+ throw new IllegalArgumentException (
306
+ "Cannot find elements when name tag name is null." );
307
+
308
+ this .tagName = tagName ;
322
309
}
323
310
324
311
@ Override
325
312
public List <WebElement > findElements (SearchContext context ) {
326
313
if (context instanceof FindsByTagName )
327
- return ((FindsByTagName ) context ).findElementsByTagName (name );
328
- return ((FindsByXPath ) context ).findElementsByXPath (".//" + name );
314
+ return ((FindsByTagName ) context ).findElementsByTagName (tagName );
315
+ return ((FindsByXPath ) context ).findElementsByXPath (".//" + tagName );
329
316
}
330
317
331
318
@ Override
332
319
public WebElement findElement (SearchContext context ) {
333
320
if (context instanceof FindsByTagName )
334
- return ((FindsByTagName ) context ).findElementByTagName (name );
335
- return ((FindsByXPath ) context ).findElementByXPath (".//" + name );
321
+ return ((FindsByTagName ) context ).findElementByTagName (tagName );
322
+ return ((FindsByXPath ) context ).findElementByXPath (".//" + tagName );
336
323
}
337
324
338
325
@ Override
339
326
public String toString () {
340
- return "By.tagName: " + name ;
327
+ return "By.tagName: " + tagName ;
341
328
}
342
329
}
343
330
@@ -348,6 +335,10 @@ public static class ByXPath extends By implements Serializable {
348
335
private final String xpathExpression ;
349
336
350
337
public ByXPath (String xpathExpression ) {
338
+ if (xpathExpression == null )
339
+ throw new IllegalArgumentException (
340
+ "Cannot find elements when the XPath expression is null." );
341
+
351
342
this .xpathExpression = xpathExpression ;
352
343
}
353
344
@@ -374,6 +365,10 @@ public static class ByClassName extends By implements Serializable {
374
365
private final String className ;
375
366
376
367
public ByClassName (String className ) {
368
+ if (className == null )
369
+ throw new IllegalArgumentException (
370
+ "Cannot find elements when the class name expression is null." );
371
+
377
372
this .className = className ;
378
373
}
379
374
@@ -417,37 +412,41 @@ public static class ByCssSelector extends By implements Serializable {
417
412
418
413
private static final long serialVersionUID = -3910258723099459239L ;
419
414
420
- private final String selector ;
415
+ private final String cssSelector ;
421
416
422
- public ByCssSelector (String selector ) {
423
- this .selector = selector ;
417
+ public ByCssSelector (String cssSelector ) {
418
+ if (cssSelector == null )
419
+ throw new IllegalArgumentException (
420
+ "Cannot find elements when the selector is null" );
421
+
422
+ this .cssSelector = cssSelector ;
424
423
}
425
424
426
425
@ Override
427
426
public WebElement findElement (SearchContext context ) {
428
427
if (context instanceof FindsByCssSelector ) {
429
428
return ((FindsByCssSelector ) context )
430
- .findElementByCssSelector (selector );
429
+ .findElementByCssSelector (cssSelector );
431
430
}
432
431
433
432
throw new WebDriverException (
434
- "Driver does not support finding an element by selector: " + selector );
433
+ "Driver does not support finding an element by selector: " + cssSelector );
435
434
}
436
435
437
436
@ Override
438
437
public List <WebElement > findElements (SearchContext context ) {
439
438
if (context instanceof FindsByCssSelector ) {
440
439
return ((FindsByCssSelector ) context )
441
- .findElementsByCssSelector (selector );
440
+ .findElementsByCssSelector (cssSelector );
442
441
}
443
442
444
443
throw new WebDriverException (
445
- "Driver does not support finding elements by selector: " + selector );
444
+ "Driver does not support finding elements by selector: " + cssSelector );
446
445
}
447
446
448
447
@ Override
449
448
public String toString () {
450
- return "By.cssSelector: " + selector ;
449
+ return "By.cssSelector: " + cssSelector ;
451
450
}
452
451
}
453
452
}
0 commit comments