Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | 11x 11x | /** * The `$$` command is a short way to call the [`findElements`](/docs/api/webdriver.html#findelements) command in order * to fetch multiple elements on the page. It returns an array with element results that will have an * extended prototype to call action commands without passing in a selector. However if you still pass * in a selector it will look for that element first and call the action on that element. * * Using the wdio testrunner this command is a global variable else it will be located on the browser object instead. * * You can chain `$` or `$$` together in order to walk down the DOM tree. For more information on how * to select specific elements, see [`Selectors`](/docs/selectors.html). * * <example> :index.html <ul id="menu"> <li><a href="/">Home</a></li> <li><a href="/">Developer Guide</a></li> <li><a href="/">API</a></li> <li><a href="/">Contribute</a></li> </ul> :$.js it('should get text a menu link', () => { const text = $$('#menu')[0]; console.log(text.$$('li')[2].$('a').getText()); // outputs: "API" }); it('should get text a menu link - JS Function', () => { const text = $$(function() { // Arrow function is not allowed here. // this is Window https://developer.mozilla.org/en-US/docs/Web/API/Window // TypeScript users may do something like this // return (this as Window).document.querySelectorAll('#menu') return this.document.querySelectorAll('#menu'); // Element[] })[0]; console.log(text.$$('li')[2].$('a').getText()); // outputs: "API" }); * </example> * * @alias $$ * @param {String|Function} selector selector or JS Function to fetch multiple elements * @return {Element[]} * @type utility * */ import { findElements } from '../../utils' import { getElements } from '../../utils/getElementObject' export default async function $$ (selector) { const res = await findElements.call(this, selector) return getElements.call(this, selector, res) } |