Currently Browsing

Author Archive

Selenium – How to check if an element has focus


We have a contact form with Name, Email and Comment fields, and if invalid data is entered to the fields, the validation system will highlight that field and it will be focused, so the user can change it quickly. In our tests we want to check if the proper field gets the focus.

<div class="contact-form">
    <label> Name </label>
    <input id="contact-name" type="text" />
    <label> Email </label>
    <input id="contact-email" type="text" />
    <label> Comment </label>
    <input id="contact-comment" type="text" />

(this is just an example code, and not a functional one)


Selenium suggest to use css selectors, so we will start with that. To see if the element has the focus we will use css pseudo-class “:focus” and check if an element is present like this:


This looks quite nice and easy, but you may encounter some problems with it. The element #contact-name can be found, but #contact-name:focus can not. In this case we have to think outside of the box, and come up with another solution. We can use the Javascript DOM locator to get the element that is selected (has focus), and compare it to the element we expect to have focus:


Binding data with Spring Forms

Spring has its own tag library, which makes JSPs easier to develop, maintain and read. One of these libraries is the form tag library, and in this post we’ll demonstrate how to use it.

For this we will use a sample project that will let us modify the user’s account details. In order to display the stored values for the account in the form, we have previously tied an object named foo to the session that holds all the information about our user’s account.

The form used for displaying and sending the account data is displayed here:

<form action="/account" method="post">
	<legend>Edit account information:</legend>
			<td><label for="name" >Name:</label></td>
			<td><input type="text" id="name" name="name" value=${} /></td>
			<td><label for="email">E-mail:</label></td>
			<td><input type="text" id="email" name="email" value=${} /></td>
			<td><label for="website">Website:</label></td>
			<td><input type="text" id="website" name="website" value=${} /></td>
		<tr><td>&nbsp;</td><td><input type="submit" value="Save" /></td></tr>

Now lets do the implementation of the form tag library on this code:

Servlet Mapping for Google App Engine and Spring

This post is all about Spring MVC 3 and Google App Engine and their interaction.

The starting point for this project was the Google App Engine’s documentation, the Google Eclipse plugin, and some tutorials found on various sites.

After reading all about the App Engine and Spring, the first thing to do was to create a project in our favorite editor, Eclipse. This generated some necessary files, and gave us a good starting point. As we want to use Spring to perform all its magic, we’ve created a web.xml like this: