One often doubt while working with selenium

APR 09

One of the common issue faced by all those working with Selenium is focusing issue. While interacting with web the users need to find the web content. The concept can be better understood with the help of a login example.


A login screen basically contains three text fields for Client Id, Usercode and Password. Client Id is retrieved from database 1 and password from database

After a user enters Client Id, Usercode and Password the pointer again return back to Client Id. In this case when the user presses login button Usercode and Password get refreshed which creates issues with login. To avoid such problems mouse pointer needs to be focussed before entering to Usercode and Password data.

Solution to the problem

Find Element command serves as an effective way to solve this issue of finding a web element to be focussed within a page. To focus on multiple web elements Find Elements command can be used. One of the way for uniquely focussing a web element within a page is by using XPATH.

Syntax for Find Element



JavascriptExecutor js = (JavascriptExecutor) driver;





WebElement login=driver.findElement(By.xpath("//input[@type='submit'and