Selenium WebDriver: Finding an Element Using SenseTalk

By Bekki Freeman | 2/7/18

One of the challenges in setting up tests with Selenium WebDriver is determining the best locator for an element. Eggplant Functional and SenseTalk provide several ways to locate elements. The Selenium community recommends CSS Selector as the best method for locating elements. It's powerful in that it can identify elements based on classes, identifiers, where they fall in the DOM hierarchy, etc.

The following SenseTalk expressions ...

set myElement to findelement(webCssSelector: "ul.schedules__list:first-child a")
put element's attribute("href")

... will locate the ‘a’ tag for the first element in the list and print its href to screen.

<ul class="schedules__list">
  <li>
<a href="http://www.example.com"><span class="schedule__route--name">Union Station</span></a></li>
  <li><a href="http://www.example.com"><span class="schedule__route--name">Westminster Station</span></a></li>
  <li><a href="http://www.example.com"><span class="schedule__route--name">Littleton-Mineral Station</span></a></li>
</ul>

A full specification of CSS Selectors can be found at w3schools.  

SenseTalk also supports several other ways to locate an element in the DOM of a webpage using Selenium WebDriver:

  • webID: Use this property to locate an element by the value of its ID attribute.
  • webName: Use this property to locate an element by the value of its Name attribute.
  • webTagName: Use this property to locate an element whose HTML tag is equal to the given value.
  • webClassName: Use this property to locate an element by the value of its Class attribute.
  • webLinkText: Use this property to locate a link whose text is equal to the indicated value.
  • webPartialLinkText: Use this property to locate a link whose text contains the indicated value.
  • webCssSelector: Use this property to locate an element using the indicated CSS selector expression.
  • webXPath: Use this property to locate an element by using an XPath expression.

You can access detailed documentation about finding web elements with SenseTalk and WebDriver on our documentation page.

Topics: sensetalk, Functional testing, Software test automation, Selenium WebDriver, test automation strategy

Bekki Freeman

Written by Bekki Freeman

A full-stack software engineer, Bekki is actively resisting the Boulder tech-hipster stereotype, even though she likes snowboarding, cycling, and craft beer (and might drive a Subaru). She’s also fluent in sarcasm and Objective-C.

Stay up-to-date with the latest in test automation

Lists by Topic

see all