Find “Cursor” position or currently focused element in a web page with Selenium
Problem Statement: On your registration page, you entered valid values in a few mandatory fields but submit the form with no values in a few of the mandatory fields. Now along with the error message(s), you want to verify that your cursor position is in the correct field (current focused element) like in the first blank mandatory field using Selenium.
There are many ways to validate that but the simplest one would be to use:> driver.switchTo().activeElement()
The Web Element with focus, or the body element if no element with the focus can be detected.
And then you can put assertion based on your expected focused element, something like:
#testAutomation #seleniumJava #focusedElement #automationTest #anotherStory