@@ -247,8 +247,8 @@ public void assignIdToElement(String locator, String id) {
247
247
.executeScript (String .format ("arguments[0].id = '%s';" , id ), elements .get (0 ));
248
248
}
249
249
250
- @ RobotKeyword ("Verify the element identified by ``locator`` is found on the current page \r \n " +
251
- "\r \n " +
250
+ @ RobotKeyword ("Verify the element identified by ``locator`` is enabled \r \n " +
251
+ "\r \n " +
252
252
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about log levels and locators." )
253
253
@ ArgumentNames ({ "locator" })
254
254
public void elementShouldBeEnabled (String locator ) {
@@ -257,7 +257,7 @@ public void elementShouldBeEnabled(String locator) {
257
257
}
258
258
}
259
259
260
- @ RobotKeyword ("Verify the element identified by ``locator`` is disabled.\r \n " +
260
+ @ RobotKeyword ("Verify the element identified by ``locator`` is disabled.\r \n " +
261
261
"\r \n " +
262
262
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators." )
263
263
@ ArgumentNames ({ "locator" })
@@ -267,6 +267,16 @@ public void elementShouldBeDisabled(String locator) {
267
267
}
268
268
}
269
269
270
+ @ RobotKeyword ("Verify the element identified by ``locator`` is focused\r \n " +
271
+ "\r \n " +
272
+ "Key attributes for arbitrary elements are id and name. See `Introduction` for details about log levels and locators." )
273
+ @ ArgumentNames ({ "locator" })
274
+ public void elementShouldBeFocused (String locator ) {
275
+ if (!isFocused (locator )) {
276
+ throw new SeleniumLibraryNonFatalException (String .format ("Element %s is not focused." , locator ));
277
+ }
278
+ }
279
+
270
280
@ RobotKeyword ("Verify the element identified by ``locator`` is selected.\r \n " +
271
281
"\r \n " +
272
282
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators." )
@@ -419,18 +429,32 @@ public void elementTextShouldNotBe(String locator, String text, String...params)
419
429
"\r \n " +
420
430
"The ``attribute_locator`` consists of element locator followed by an @ sign and attribute name. Example: element_id@class\r \n " +
421
431
"\r \n " +
422
- "Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators." )
432
+ "Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.\r \n " +
433
+ "\r \n " +
434
+ "Passing attribute name as part of the locator was removed in SeleniumLibrary 3.2. The explicit attribute argument should be used instead." )
423
435
@ ArgumentNames ({ "attributeLocator" })
436
+ @ Deprecated
424
437
public String getElementAttribute (String attributeLocator ) {
425
438
String [] parts = parseAttributeLocator (attributeLocator );
439
+ return getElementAttribute (parts [0 ], parts [1 ]);
440
+ }
441
+
442
+ @ RobotKeyword ("Returns value of attribute from element locator.\r \n " +
443
+ "\r \n " +
444
+ "See the `Locating elements` section for details about the locator syntax.\r \n " +
445
+ "\r \n " +
446
+ "Example: ${id}= Get Element Attribute css:h1 id\r \n " +
447
+ "\r \n " +
448
+ "Passing attribute name as part of the locator was removed in SeleniumLibrary 3.2. The explicit attribute argument should be used instead." )
449
+ @ ArgumentNames ({ "locator" , "attribute" })
450
+ public String getElementAttribute (String locator , String attribute ) {
426
451
427
- List <WebElement > elements = elementFind (parts [ 0 ] , true , false );
452
+ List <WebElement > elements = elementFind (locator , true , false );
428
453
429
454
if (elements .size () == 0 ) {
430
- throw new SeleniumLibraryNonFatalException (String .format ("Element '%s' not found." , parts [ 0 ] ));
455
+ throw new SeleniumLibraryNonFatalException (String .format ("Element '%s' not found." , locator ));
431
456
}
432
-
433
- return elements .get (0 ).getAttribute (parts [1 ]);
457
+ return elements .get (0 ).getAttribute (attribute );
434
458
}
435
459
436
460
@ RobotKeyword ("Clears the text from element identified by ``locator``.\r \n " +
@@ -582,11 +606,20 @@ public void doubleClickElement(String locator) {
582
606
action .doubleClick (elements .get (0 )).perform ();
583
607
}
584
608
585
- @ RobotKeyword ("Set the focus to the element identified by ``locator``.\r \n " +
586
- "\r \n " +
609
+ @ RobotKeyword ("Set the focus to the element identified by ``locator``.\r \n " +
610
+ "\r \n " +
587
611
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators." )
588
612
@ ArgumentNames ({ "locator" })
613
+ @ Deprecated
589
614
public void focus (String locator ) {
615
+ setFocusToElement (locator );
616
+ }
617
+
618
+ @ RobotKeyword ("Set the focus to the element identified by ``locator``.\r \n " +
619
+ "\r \n " +
620
+ "Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators." )
621
+ @ ArgumentNames ({ "locator" })
622
+ public void setFocusToElement (String locator ) {
590
623
List <WebElement > elements = elementFind (locator , true , true );
591
624
((JavascriptExecutor ) browserManagement .getCurrentWebDriver ()).executeScript ("arguments[0].focus();" ,
592
625
elements .get (0 ));
@@ -977,6 +1010,14 @@ protected boolean isEnabled(String locator) {
977
1010
return true ;
978
1011
}
979
1012
1013
+ protected boolean isFocused (String locator ) {
1014
+ List <WebElement > elements = elementFind (locator , true , true );
1015
+ WebElement element = elements .get (0 );
1016
+ WebDriver current = browserManagement .getCurrentWebDriver ();
1017
+ WebElement focused = current .switchTo ().activeElement ();
1018
+ return element .equals (focused );
1019
+ }
1020
+
980
1021
protected boolean isVisible (String locator ) {
981
1022
List <WebElement > elements = elementFind (locator , true , false );
982
1023
if (elements .size () == 0 ) {
0 commit comments