How to identify elements in Robot Framework

How to identify the elements in Robot Framework:


Element identification in Robot Framework is different than we do in Selenium. Robot Framework has different keywords to deal with elements in your test automation.

Here are some Keywords from Robot Framework, So, The above listed Keywords need element identifiers to act on the element. Robot Framework uses 2 types of strategies to identify the elements.

Robot Framework Element identification Strategies:
  • Default Locator Strategy
  • Explicit Locator Strategy

How to send locators to keywords of Robot Framework
`Click Element     q`
If you observe the statement we are not specifying what kind of identifier is `q`. Robot Framework can handle some identifiers, though the type of identification is not provided to the Keyword. This is called Default locator strategy. But some type of identifiers need the identifier type that is called Explicit Locator Strategy.

Lets see some examples,
  • `Click Element    q`
  • `Click Element    //div`
  • `Click Link     ContactUs`
  • `Click Element    css:.searchWidget`

Default Locator Strategy:
Click Element   q
In the example 1, Robot Framework can identify the element given the identifier is either id or name. In case of example 2, the identifier we have provided is an xpath, but we didn’t specify it as xpath://div. Because xpath starts with //, so Robot framework can understand it as an xpath. So while using default locator strategy different elements uses different default locators. In case of `Click Link     ContactUs`, ContactUs is link text of the link. Link text can only be used with links only. Similar way an image element can use `src`. Id and name can be used with all the elements.

Some examples are:
  • Link can accept id, name, link text and href
  • Image can accept id, name and src
  • Button can accept id, name and value

Explicit Locator Strategy:
Click Element    css:.searchWidget

In the above example, we have explicitly specified the identifier type `css` to tell the keyword to find the element using css. This is called explicit locator strategy. There are different type of element identifiers. examples : id, name, class, css, tag, xpath, dom, link, partial link, etc…

Please always use latest version of library to get more features. For full documentation of keywords and identifiers please go through seleniumLibrary : SeleniumLibrary

This is from my personal learnings. Thanks for reading. Happy learning.

Comments