Skip to content

Latest commit

 

History

History
116 lines (91 loc) · 2.14 KB

elements.md

File metadata and controls

116 lines (91 loc) · 2.14 KB

Elements

Elements has "lazy" interface (as it was in protractor)

searchStragegy

const { seleniumWD } = require('promod');
const { By, $$ } = seleniumWD;
// css
const elementsByCss = $$('.class #id div a[href*="link"]'); // css selector
const elementsByXpath = $$('xpath=.//div[@data-test="id"]/span'); // xpath selector
const elementsByJS = $$(() => document.querySelectorAll("div>span")); // js selector
const elementWithByInterface = $$(By.className('class')); // By object interface

get

const { seleniumWD } = require('promod');
const { $$ } = seleniumWD;
const someInput = $$('input').get(3);

(async () => {
  await someInput.sendKeys('some value');
})();

first

const { seleniumWD } = require('promod');
const { $$ } = seleniumWD;
const someButton = $$('button').first();

(async () => {
  await someButton.click();
})();

last

const { seleniumWD } = require('promod');
const { $$ } = seleniumWD;
const someButton = $$('button').last();

(async () => {
  await someButton.click();
})();

each

	const {seleniumWD} = require('promod');
	const {$$} = seleniumWD
	const someButtons = $$('button');

	;(async () => {
		await someButtons.each((someButton) => {
			await someButton.click()
		})
	})()

map

	const {seleniumWD} = require('promod');
	const {$$} = seleniumWD
	const someButtons = $$('button');

	;(async () => {
		const allButtonTexts = await someButtons.map((button) => {
			return await someButton.getText()
		})
	})()

some

	const {seleniumWD} = require('promod');
	const {$$} = seleniumWD
	const someButtons = $$('button');

	;(async () => {
		const isSomeButtonVisible = await someButtons.some((button) => {
			return await someButton.isDisplayed()
		})
	})()

every

	const {seleniumWD} = require('promod');
	const {$$} = seleniumWD
	const someButtons = $$('button');

	;(async () => {
		const isEveryButtonVisible = await someButtons.every((button) => {
			return await someButton.isDisplayed()
		})
	})()