WebDriver Selectors

Some commands require a target DOM element to operate on, specified in the
target
argument element of the
command
element. Such targets can be links to click,
div
to hover over and windows or tabs to switch to and so on. In cases when selectors find more elements, only the first one found will be used. Be advised to use selectors as specific as possible to make sure they match only one element, being the one you want. If the command requires the
target
but it’s empty in your script, it’s equal to
tag=body
, the page
body
element is used. If
target
contents start with a double slash (//), the XPath selector is assumed.
ASM Webdriver supports the following selectors to find the target:
  • id
    =elementId
    ID selector: This selector will match DOM element having
    id=”elementId”
    in the DOM page structure.
  • css
    =div.someClass p
    CSS selector: This example selector will mach
    <p>
    element inside
    <div>
    element with
    class=”someClass”
    .  Every expression supported by Selenium ByCssSelector method works in ASM Webdriver monitor.
  • xpath
    =//img[@title=’Nice image’]
    XPath selector: This example will match an <img> element with the “Nice image” string in its
    title
    attribute. For more information, see the XPath specification.
  • name
    =password
    Name selector: This example finds an element having a
    name
    attribute set to
    ”password”
    . Useful for locating form elements that usually have the
    name
    attribute set.
  • link
    =Home
    Link text selector. This example will match
    <a>
    element that has Home text inside, such as
    <a href=”/”>Home</a>
    .
  • partialLink
    =click
    Partial link text selector works similar to the
    link
    but you need not specify the whole text, but only a substring is required. For example,
    <a href=”/”>click here to go to Home page</a>
    .
  • tag
    =img
    Tag name selector selects by tag name. This selector is particularly prone to find more elements but only the first one will be operated on so use with caution.
  • class
    =wrapper
    Class name selector, selects by class attribute. Again, this selector will probably find more elements so use with caution. This example is equal to the
    css=.wrapper
    selector.
  • script
    =return document.getElementById(‘main-content’)
    Script selector. You can use Javascript to locate and return your element if it is not convenient to use any other supported selector.
  • identifier
    =someId
    Works the same as id selector. Included for compatibility reasons.
  • title
    =windowTitle
    Title selector. Only useful for switching windows (
    selectWindow
    command)
  • index
    =1
    Index selector. Only works when switching frames. (
    selectFrame
    command)
  • relative
    =parent
    The relative selector to switch back to the parent frame. The only value allowed after the equals sign is
    “parent”
    , as shown. Only for
    selectFrame
    command.