Selenium IDE | Locating Elements

Locating Elements

Selenium IDE | Locating the Elements

For many Selenium IDE commands, a target is required. This target identifies an element in the content of the web application and consists of the location strategy followed by the location in the format locatorType=location. The locator type can be omitted in many cases. The various locator types are explained below with examples for each.

  • Locating by Identifier: This is probably the most common method of locating elements and is the catch-all default when no recognized locator type is used With this strategy, the first element with the id attribute value matching the location will be used. If no element has a matching id attribute, then the first element with a name attribute matching the location will be used.

For instance, page source could have id and name attributes as follows:

<html>

<body>

<form id=”loginForm”>

<input name=”username” type=”text” />

<input name=”password” type=”password” />

<input name=”continue” type=”submit” value=”Login” />

</form>

</body>

<html>

The following locator strategies would return the elements from the HTML snippet above indicated by line number:

  • identifier=loginForm (3)
  • identifier=password (5)
  • identifier=continue (6)
  • continue (6)

Since the identifier type of locator is the default, the identifier= in the first three examples above is not necessary.

  • Locating by Id: This type of locator is more limited than the identifier locator type, but also more explicit. Use this when you know an element’s id attribute.

<html>

<body>

<form id=”loginForm”>

<input name=”username” type=”text” />

<input name=”password” type=”password” />

<input name=”continue” type=”submit” value=”Login” />

<input name=”continue” type=”button” value=”Clear” />

</form>

</body>

<html>

id=loginForm (3)

  • Locating by Name: The name locator type will locate the first element with a matching name attribute. If multiple elements have the same value for a name attribute, then you can use filters to further refine location strategy. The default filter type is value (matching the value attribute).

<html>

<body>

<form id=”loginForm”>

<input name=”username” type=”text” />

<input name=”password” type=”password” />

<input name=”continue” type=”submit” value=”Login” />

<input name=”continue” type=”button” value=”Clear” />

</form>

</body>

<html>

  • name=username (4)
  • name=continue value=Clear (7)
  • name=continue Clear (7)
  • name=continue type=button (7)

This topic covers the following modules:

Selenium professional free practice test

Go back to Tutorial                                                                                Go to Home Page

Share this post
[social_warfare]
Selenium IDE | Test Suits & Commonly Used Selenium Commands
Selenium Tutorials Selenium IDE | Locating by XPath

Get industry recognized certification – Contact us

keyboard_arrow_up