Description
This Selenium extension can be used to check if an HTML element has the focus or not.
HasFocus provides two commands which both need a locator which targets to an element.
The first command is assertHasFocus and is used to check if an element has the focus. If the element has not the focus, this command will fail.
The second command is assertNotHasFocus what does the opposite of assertHasFocus. It will fail when the element has the focus.
Both commands use Seleniums default element location mechanism why there is no difference in the use of locators to other common Selenium commands.
For an example please refer the test case which is contained in the directory tests inside the zip archive of this extension.
Example Of Use
| assertHasFocus |
name=myTextField |
Checks that the inputfield with the name myTextField has the focus. |
| assertNotHasFocus |
myDropdownBox |
Checks that the dropdownbox with the id myDropdownBox has not the focus. |
Notes
Please be aware that the javascript used by this extension is not compatible to Firefox versions lower 3.x.x.
This extension was successfully tested with Selenium Core 1.0.2 on Firefox 3.6.6 and the Internet Explorer 6.0
Please leave a note if you were successful in executing this extension on any other environment.
License
Licensed under the Apache License, Version 2.0 (the "License")
Download
Download this extension with just a click on HasFocus.zip.
The downloaded zip archive contains the file user-extensions.js.hasFocus whose code must be copied into you user-extensions.js. After doing this the above introduced commands are ready to use.
