Generic Accessor Functions
_activeElement
Section titled “_activeElement”- Since
- Sahi Pro 4.0
Modes Browser
_activeElement()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
HTML DOM element | Element in focus |
Used to verify if the specific element is the one in focus. Eg
_assertEqual(_texbox("user"), _activeElement());- Since
- Sahi Pro 3.5
Modes Browser
_byId($id)Arguments
| Name | Type | Description |
|---|---|---|
$id | string | id of element |
Returns
HTML DOM element | Element matching with the specified id |
Used to find elements solely by id without using its tagName information.
<div id="errormsg">Error</div>_byId("errormsg") // points to the above tag. Note that the tagName "div" is not used here._byText (Deprecated)
Section titled “_byText (Deprecated)”- Since
- Sahi Pro 3.5
Modes Browser
_byText($text, $tagName)Arguments
| Name | Type | Description |
|---|---|---|
$text | string | text of element |
$tagName | string | tagName of element which has this text. eg. "DIV" |
Returns
HTML DOM element | Element matching with the specified text and tagName |
Used to find element by text and tagName
<div id="errormsg">some text</div>_byText("some text", "DIV") // points to the above tag._byClassName (Deprecated)
Section titled “_byClassName (Deprecated)”- Since
- Sahi Pro 3.5
Modes Browser
_byClassName($className, $tagName[, $relations])Arguments
| Name | Type | Description |
|---|---|---|
$className | string | className of element |
$tagName | string | tagName of element which has this text. eg. "DIV" |
$relations | relationoptional | DOM or Positional Relations |
Returns
HTML DOM element | Element matching with the specified className and tagName |
Finds element by className with given tagName and constrained by given relations
<div class="bigfont">Some text</div>_byClassName("bigfont", "DIV")_byXPath
Section titled “_byXPath”- Since
- Sahi Pro 3.5
Modes Browser
_byXPath($xpath)Arguments
| Name | Type | Description |
|---|---|---|
$xpath | string | XPath of element |
Returns
HTML DOM element | Element matching with the specified xpath |
Eg.
_byXPath("//table[3]//tr[1]/td[2]")_byXPath("//tr[1]/td[2]")This is a convenience method for people moving from Selenium or other tools to Sahi.
_accessor
Section titled “_accessor”- Since
- Sahi Pro 3.5
Modes Browser
_accessor($string)Arguments
| Name | Type | Description |
|---|---|---|
$string | string | String to eval |
Returns
HTML DOM element | Element |
This function just evaluates the string and returns a dom object. Eg. _accessor("document.formName.elementName"). This function is not very useful.
_bySeleniumLocator
Section titled “_bySeleniumLocator”- Since
- Sahi Pro 3.5
Modes Browser
_bySeleniumLocator($locator)Arguments
| Name | Type | Description |
|---|---|---|
$locator | string | selenium locator |
Returns
null |
Allows identification of elements using some Selenium locators. Use only while migrating from Selenium to Sahi.

