Go down
Posts : 3
Join date : 2009-09-23

How to create/recognize object element not using recording?

on Wed Sep 23, 2009 4:17 am

I have the following questions:

1. How to create an object element not using recording method?
for example, by scripting
Go (image link)

Will Selenium find the Go link on the page? Can we use the labels on the screen to run as many actions as we like this way?

2. How Selenium recognize a UI element?


Posts : 383
Join date : 2009-07-30
Location : India

Re: How to create/recognize object element not using recording?

on Wed Sep 23, 2009 10:58 am

If you want to create script manually not using record and play feature of selenium, it is simple.

For this you have to start you application and IDE. Suppose you have login page and you want to create object for all object present on that screen. The following are steps:

1. go to first element username field, right click with mouse. It will show some command of selenium in mouse popup. select verifyElementPresent.
2. Moe one step is recorded in selenium ide. go and have a look.
3. Now modify that command, do type instead of verifyElement.
4. leave the Target field, it is your object locator.
5. Type username in value option of IDE.

By this way you can get object of any element and modify according to your need. Selenium will not find "GO" you have to provide actual dom locator or xpath.

Selenium will recognize the element in following ways:

Element Locators tell Selenium which HTML element a command refers to.
The format of a locator is:

We support the following strategies for locating elements:

Select the element with the specified @id attribute. If no match is
found, select the first element whose @name attribute is id.
(This is normally the default; see below.)
Select the element with the specified @id attribute.
Select the first element with the specified @name attribute.

  • username
  • name=username

The name may optionally be followed by one or more element-filters, separated from the name by whitespace. If the filterType is not specified, value is assumed.

  • name=flavour value=chocolate


Find an element using Javascript traversal of the HTML Document Object
Model. DOM locators must begin with "document.".

  • dom=document.forms['myForm'].myDropdown
  • dom=document.images[56]

Locate an element using an XPath expression.

  • xpath=//img[@alt='The image alt text']
  • xpath=//table[@id='table1']//tr[4]/td[2]

Select the link (anchor) element which contains text matching the
specified pattern.

  • link=The link text

Select the element using css selectors. Please refer to CSS2 selectors, CSS3 selectors
for more information. You can also check the TestCssLocators test in
the selenium test suite for an example of usage, which is included in
the downloaded selenium core package.

  • css=a[href="#id3"]
  • css=span#firstChild + span

Currently the css selector locator supports all css1, css2 and css3
selectors except namespace in css3, some pseudo classes(:nth-of-type,
:nth-last-of-type, :first-of-type, :last-of-type, :only-of-type,
:visited, :hover, :active, :focus, :indeterminate) and pseudo
elements(::first-line, ::first-letter, ::selection, ::before, ::after).

Without an explicit locator prefix, Selenium uses the following default

  • dom, for locators starting with "document."

  • xpath, for locators starting with "//"

  • identifier, otherwise

Hope this will help you. Best of luck.

Posts : 3
Join date : 2009-09-23

Re: How to create/recognize object element not using recording?

on Wed Sep 23, 2009 11:38 am
Hi Adviser,

Thanks for the detailed explainations and I found the context menu by following your steps. It is so helpful!

Active particpant
Active particpant
Posts : 10
Join date : 2009-11-06

Re: How to create/recognize object element not using recording?

on Sat Nov 07, 2009 2:48 pm
Hi Maggie

U may use Firebug addon in FF. Through this u can know the locators. Capture them and type the command u want to perform on them
Sponsored content

Re: How to create/recognize object element not using recording?

Back to top
Permissions in this forum:
You cannot reply to topics in this forum