appium-dom-utils
Version:
Appium utils implemented with DOM
57 lines (43 loc) • 1.86 kB
Markdown
[](https://www.npmjs.com/package/appium-dom-utils) [](https://npm-stat.com/charts.html?package=appium-dom-utils)[](https://github.com/testimio/appium-dom-utils/blob/master/LICENSE)
```
npm i -S appium-dom-utils
```
A collection of util functions for writing Appium tests using DOM API.
```js
const {
parseDomFromString,
getXPathSelector,
} = require('appium-dom-utils');
const wdio = require("webdriverio");
const client = await webdriverio.remote(opts);
const xmlSourceString = await client.getPageSource();
const dom = parseDomFromString(xmlSourceString);
const domElement = dom.querySelector("[text*='9']");
const xpath = getXPathSelector(domElement);
const appiumElement = await client.$(xpath);
await appiumElement.click();
await client.deleteSession();
```
Returns a DOM object.
Throws when the xml string is not formatted well.
Currently tested with the return value of driver.getPageSource() for both Android (UiAutomator2) and iOS (UIAutomation) tests.
```js
import { parseDomFromString } from 'appium-dom-utils';
parseDomFromString(xmlString);
```
Returns the xpath (string) for the element supplied. [Android UiAutomator2 tests].
```js
import { getXPathSelector } from 'appium-dom-utils';
getXPathSelector(element);
```
Returns the class chain (string) for the element supplied. [iOS UIAutomation tests].
```js
import { getClassChainSelector } from 'appium-dom-utils';
getClassChainSelector(element);
```