Finding WebElements
When writing SenseTalk scripts for testing based on Selenium WebDriver connections, much of your effort is likely to be based around interacting with various HTML elements in the Document Object Model (DOM) of the pages you're testing. These elements in the DOM are often referred to as WebElement objects.
SenseTalk includes several commands and functions that provide you with different ways to locate WebElements within your pages so that you can take some action, find information, or perform verification against those elements.
WebElement Identifiers
To access a WebElement within the DOM, such as when using the FindElement()
function or the Click
command with a WebDriver connection, you have several ways to specify the element you want to interact with. The following WebElement Identifiers can be used to locate elements in the DOM:
- 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. For information about XPath and XPath expressions, see XPath in Selenium WebDriver: Complete Tutorial.
WebElement Objects
A successful WebElement search creates a WebElement object. The object contains a property list with information about the element that was found. A WebElement object can include any properties from the following list, but not all properties will necessarily return values. The specific WebElement type determines which properties have useful values.
- Text: The visible text contained in the element that is displayed in the browser.
- tagName: The HTML tag name of the element.
- Name: The value of the Name attribute of the element.
- ID: The value of the ID attribute of the element.
- Class: The value of the Class attribute of the element.
- Attribute(): Returns the value of a specific attribute of the element, or is empty if that attribute is not present.
- isSelected: Returns
True
orFalse
to indicate whether the element is selected in the browser. - isEnabled: Returns
True
orFalse
to indicate whether the element is enabled in the browser. - isDisplayed: Returns
True
orFalse
to indicate whether the element is displayed in the browser. - Origin: Returns a webLocation property list of the element's origin (top left corner) within the page. For example:
(objectType:"webLocation", x:"262", y:"323")
- Size: Returns the size (width, height) of the element within the page.
- Rectangle: Returns the rectangle (x1, y1, x2, y2) of the element within the page. Note that these are browser coordinates, not screen coordinates.
- cssProperty: Returns the value of the specified CSS property of the element.
- WebDriver: Returns the WebDriverConnection object for the WebDriver connection containing the element.
- WebContext: Returns either the WebDriverConnection object for the WebDriver connection containing the element, or the WebElement object within which the given element was found.
WebElement objects can display in either long or short formats when they are called, i.e., in the results log of a run. The long format is the default, and automatically displays the values of several properties. Note that the long format requires additional requests to the WebDriver server each time the WebElement object displays.
Change the webElementDisplay
global property to short
to display WebElements using the short format. Note that if an element is not available in the current page context, the WebElement object displays in short format even if the WebElementDisplay
is set to long.