@@ -48,47 +48,47 @@ public abstract class By {
48
48
* @param id The value of the "id" attribute to search for.
49
49
* @return A By which locates elements by the value of the "id" attribute.
50
50
*/
51
- public static By id (final String id ) {
51
+ public static By id (String id ) {
52
52
return new ById (id );
53
53
}
54
54
55
55
/**
56
56
* @param linkText The exact text to match against.
57
57
* @return A By which locates A elements by the exact text they display.
58
58
*/
59
- public static By linkText (final String linkText ) {
59
+ public static By linkText (String linkText ) {
60
60
return new ByLinkText (linkText );
61
61
}
62
62
63
63
/**
64
64
* @param partialLinkText The partial text to match against
65
65
* @return a By which locates A elements that contain the given link text
66
66
*/
67
- public static By partialLinkText (final String partialLinkText ) {
67
+ public static By partialLinkText (String partialLinkText ) {
68
68
return new ByPartialLinkText (partialLinkText );
69
69
}
70
70
71
71
/**
72
72
* @param name The value of the "name" attribute to search for.
73
73
* @return A By which locates elements by the value of the "name" attribute.
74
74
*/
75
- public static By name (final String name ) {
75
+ public static By name (String name ) {
76
76
return new ByName (name );
77
77
}
78
78
79
79
/**
80
80
* @param tagName The element's tagName
81
81
* @return a By which locates elements by their tag name
82
82
*/
83
- public static By tagName (final String tagName ) {
83
+ public static By tagName (String tagName ) {
84
84
return new ByTagName (tagName );
85
85
}
86
86
87
87
/**
88
88
* @param xpathExpression The XPath to use.
89
89
* @return A By which locates elements via XPath.
90
90
*/
91
- public static By xpath (final String xpathExpression ) {
91
+ public static By xpath (String xpathExpression ) {
92
92
return new ByXPath (xpathExpression );
93
93
}
94
94
@@ -100,7 +100,7 @@ public static By xpath(final String xpathExpression) {
100
100
* @param className The value of the "class" attribute to search for.
101
101
* @return A By which locates elements by the value of the "class" attribute.
102
102
*/
103
- public static By className (final String className ) {
103
+ public static By className (String className ) {
104
104
return new ByClassName (className );
105
105
}
106
106
@@ -112,7 +112,7 @@ public static By className(final String className) {
112
112
* @param cssSelector CSS expression.
113
113
* @return A By which locates elements by CSS.
114
114
*/
115
- public static By cssSelector (final String cssSelector ) {
115
+ public static By cssSelector (String cssSelector ) {
116
116
return new ByCssSelector (cssSelector );
117
117
}
118
118
@@ -124,9 +124,9 @@ public static By cssSelector(final String cssSelector) {
124
124
*/
125
125
public WebElement findElement (SearchContext context ) {
126
126
List <WebElement > allElements = findElements (context );
127
- if (allElements == null || allElements .isEmpty ())
128
- throw new NoSuchElementException ("Cannot locate an element using "
129
- + toString ());
127
+ if (allElements == null || allElements .isEmpty ()) {
128
+ throw new NoSuchElementException ("Cannot locate an element using " + toString ());
129
+ }
130
130
return allElements .get (0 );
131
131
}
132
132
@@ -140,14 +140,13 @@ public WebElement findElement(SearchContext context) {
140
140
141
141
@ Override
142
142
public boolean equals (Object o ) {
143
- if (this == o )
144
- return true ;
145
- if (o == null || getClass () != o .getClass ())
143
+ if (!(o instanceof By )) {
146
144
return false ;
145
+ }
147
146
148
- By by = (By ) o ;
147
+ By that = (By ) o ;
149
148
150
- return toString ().equals (by .toString ());
149
+ return this . toString ().equals (that .toString ());
151
150
}
152
151
153
152
@ Override
@@ -168,27 +167,27 @@ public static class ById extends By implements Serializable {
168
167
private final String id ;
169
168
170
169
public ById (String id ) {
171
- if (id == null )
172
- throw new IllegalArgumentException (
173
- "Cannot find elements with a null id attribute." );
170
+ if (id == null ) {
171
+ throw new IllegalArgumentException ("Cannot find elements with a null id attribute." );
172
+ }
174
173
175
174
this .id = id ;
176
175
}
177
176
178
177
@ Override
179
178
public List <WebElement > findElements (SearchContext context ) {
180
- if (context instanceof FindsById )
179
+ if (context instanceof FindsById ) {
181
180
return ((FindsById ) context ).findElementsById (id );
182
- return (( FindsByXPath ) context ). findElementsByXPath ( ".//*[@id = '" + id
183
- + "']" );
181
+ }
182
+ return (( FindsByXPath ) context ). findElementsByXPath ( ".//*[@id = '" + id + "']" );
184
183
}
185
184
186
185
@ Override
187
186
public WebElement findElement (SearchContext context ) {
188
- if (context instanceof FindsById )
187
+ if (context instanceof FindsById ) {
189
188
return ((FindsById ) context ).findElementById (id );
190
- return (( FindsByXPath ) context ). findElementByXPath ( ".//*[@id = '" + id
191
- + "']" );
189
+ }
190
+ return (( FindsByXPath ) context ). findElementByXPath ( ".//*[@id = '" + id + "']" );
192
191
}
193
192
194
193
@ Override
@@ -204,9 +203,9 @@ public static class ByLinkText extends By implements Serializable {
204
203
private final String linkText ;
205
204
206
205
public ByLinkText (String linkText ) {
207
- if (linkText == null )
208
- throw new IllegalArgumentException (
209
- "Cannot find elements when link text is null." );
206
+ if (linkText == null ) {
207
+ throw new IllegalArgumentException ("Cannot find elements when link text is null." );
208
+ }
210
209
211
210
this .linkText = linkText ;
212
211
}
@@ -234,17 +233,16 @@ public static class ByPartialLinkText extends By implements Serializable {
234
233
private final String partialLinkText ;
235
234
236
235
public ByPartialLinkText (String partialLinkText ) {
237
- if (partialLinkText == null )
238
- throw new IllegalArgumentException (
239
- "Cannot find elements when link text is null." );
236
+ if (partialLinkText == null ) {
237
+ throw new IllegalArgumentException ("Cannot find elements when link text is null." );
238
+ }
240
239
241
240
this .partialLinkText = partialLinkText ;
242
241
}
243
242
244
243
@ Override
245
244
public List <WebElement > findElements (SearchContext context ) {
246
- return ((FindsByLinkText ) context )
247
- .findElementsByPartialLinkText (partialLinkText );
245
+ return ((FindsByLinkText ) context ).findElementsByPartialLinkText (partialLinkText );
248
246
}
249
247
250
248
@ Override
@@ -265,27 +263,27 @@ public static class ByName extends By implements Serializable {
265
263
private final String name ;
266
264
267
265
public ByName (String name ) {
268
- if (name == null )
269
- throw new IllegalArgumentException (
270
- "Cannot find elements when name text is null." );
266
+ if (name == null ) {
267
+ throw new IllegalArgumentException ("Cannot find elements when name text is null." );
268
+ }
271
269
272
270
this .name = name ;
273
271
}
274
272
275
273
@ Override
276
274
public List <WebElement > findElements (SearchContext context ) {
277
- if (context instanceof FindsByName )
275
+ if (context instanceof FindsByName ) {
278
276
return ((FindsByName ) context ).findElementsByName (name );
279
- return (( FindsByXPath ) context ). findElementsByXPath ( ".//*[@name = '"
280
- + name + "']" );
277
+ }
278
+ return (( FindsByXPath ) context ). findElementsByXPath ( ".//*[@name = '" + name + "']" );
281
279
}
282
280
283
281
@ Override
284
282
public WebElement findElement (SearchContext context ) {
285
- if (context instanceof FindsByName )
283
+ if (context instanceof FindsByName ) {
286
284
return ((FindsByName ) context ).findElementByName (name );
287
- return (( FindsByXPath ) context ). findElementByXPath ( ".//*[@name = '"
288
- + name + "']" );
285
+ }
286
+ return (( FindsByXPath ) context ). findElementByXPath ( ".//*[@name = '" + name + "']" );
289
287
}
290
288
291
289
@ Override
@@ -301,24 +299,26 @@ public static class ByTagName extends By implements Serializable {
301
299
private final String tagName ;
302
300
303
301
public ByTagName (String tagName ) {
304
- if (tagName == null )
305
- throw new IllegalArgumentException (
306
- "Cannot find elements when name tag name is null." );
302
+ if (tagName == null ) {
303
+ throw new IllegalArgumentException ("Cannot find elements when name tag name is null." );
304
+ }
307
305
308
306
this .tagName = tagName ;
309
307
}
310
308
311
309
@ Override
312
310
public List <WebElement > findElements (SearchContext context ) {
313
- if (context instanceof FindsByTagName )
311
+ if (context instanceof FindsByTagName ) {
314
312
return ((FindsByTagName ) context ).findElementsByTagName (tagName );
313
+ }
315
314
return ((FindsByXPath ) context ).findElementsByXPath (".//" + tagName );
316
315
}
317
316
318
317
@ Override
319
318
public WebElement findElement (SearchContext context ) {
320
- if (context instanceof FindsByTagName )
319
+ if (context instanceof FindsByTagName ) {
321
320
return ((FindsByTagName ) context ).findElementByTagName (tagName );
321
+ }
322
322
return ((FindsByXPath ) context ).findElementByXPath (".//" + tagName );
323
323
}
324
324
@@ -335,9 +335,10 @@ public static class ByXPath extends By implements Serializable {
335
335
private final String xpathExpression ;
336
336
337
337
public ByXPath (String xpathExpression ) {
338
- if (xpathExpression == null )
338
+ if (xpathExpression == null ) {
339
339
throw new IllegalArgumentException (
340
- "Cannot find elements when the XPath expression is null." );
340
+ "Cannot find elements when the XPath expression is null." );
341
+ }
341
342
342
343
this .xpathExpression = xpathExpression ;
343
344
}
@@ -365,27 +366,30 @@ public static class ByClassName extends By implements Serializable {
365
366
private final String className ;
366
367
367
368
public ByClassName (String className ) {
368
- if (className == null )
369
+ if (className == null ) {
369
370
throw new IllegalArgumentException (
370
- "Cannot find elements when the class name expression is null." );
371
+ "Cannot find elements when the class name expression is null." );
372
+ }
371
373
372
374
this .className = className ;
373
375
}
374
376
375
377
@ Override
376
378
public List <WebElement > findElements (SearchContext context ) {
377
- if (context instanceof FindsByClassName )
379
+ if (context instanceof FindsByClassName ) {
378
380
return ((FindsByClassName ) context ).findElementsByClassName (className );
379
- return ((FindsByXPath ) context ).findElementsByXPath (".//*["
380
- + containingWord ("class" , className ) + "]" );
381
+ }
382
+ return ((FindsByXPath ) context ).findElementsByXPath (
383
+ ".//*[" + containingWord ("class" , className ) + "]" );
381
384
}
382
385
383
386
@ Override
384
387
public WebElement findElement (SearchContext context ) {
385
- if (context instanceof FindsByClassName )
388
+ if (context instanceof FindsByClassName ) {
386
389
return ((FindsByClassName ) context ).findElementByClassName (className );
387
- return ((FindsByXPath ) context ).findElementByXPath (".//*["
388
- + containingWord ("class" , className ) + "]" );
390
+ }
391
+ return ((FindsByXPath ) context ).findElementByXPath (
392
+ ".//*[" + containingWord ("class" , className ) + "]" );
389
393
}
390
394
391
395
/**
@@ -398,8 +402,7 @@ public WebElement findElement(SearchContext context) {
398
402
* @return XPath fragment
399
403
*/
400
404
private String containingWord (String attribute , String word ) {
401
- return "contains(concat(' ',normalize-space(@" + attribute + "),' '),' "
402
- + word + " ')" ;
405
+ return "contains(concat(' ',normalize-space(@" + attribute + "),' '),' " + word + " ')" ;
403
406
}
404
407
405
408
@ Override
@@ -415,18 +418,17 @@ public static class ByCssSelector extends By implements Serializable {
415
418
private final String cssSelector ;
416
419
417
420
public ByCssSelector (String cssSelector ) {
418
- if (cssSelector == null )
419
- throw new IllegalArgumentException (
420
- "Cannot find elements when the selector is null" );
421
+ if (cssSelector == null ) {
422
+ throw new IllegalArgumentException ("Cannot find elements when the selector is null" );
423
+ }
421
424
422
425
this .cssSelector = cssSelector ;
423
426
}
424
427
425
428
@ Override
426
429
public WebElement findElement (SearchContext context ) {
427
430
if (context instanceof FindsByCssSelector ) {
428
- return ((FindsByCssSelector ) context )
429
- .findElementByCssSelector (cssSelector );
431
+ return ((FindsByCssSelector ) context ).findElementByCssSelector (cssSelector );
430
432
}
431
433
432
434
throw new WebDriverException (
@@ -436,8 +438,7 @@ public WebElement findElement(SearchContext context) {
436
438
@ Override
437
439
public List <WebElement > findElements (SearchContext context ) {
438
440
if (context instanceof FindsByCssSelector ) {
439
- return ((FindsByCssSelector ) context )
440
- .findElementsByCssSelector (cssSelector );
441
+ return ((FindsByCssSelector ) context ).findElementsByCssSelector (cssSelector );
441
442
}
442
443
443
444
throw new WebDriverException (
0 commit comments