GitXplorerGitXplorer
j

playwright-relative-selector

public
5 stars
1 forks
0 issues

Commits

List of commits on branch master.
Verified
831a6a8712164c9d54c38835d5a920cfc9551ff2

Monthly dependabot

jjfgreffier committed 4 years ago
Unverified
c58fff3f519e58467e0f30aafab76a3241dfc550

Bump eslint-config-prettier from 7.0.0 to 7.1.0

ddependabot[bot] committed 4 years ago
Unverified
27ac99358ba8508f6b155c404b09514349ff2ec8

Bump playwright from 1.7.0 to 1.7.1

ddependabot[bot] committed 4 years ago
Unverified
4476ca5b72b4f45a94193197f4e68605fcdb28d2

Bump eslint from 7.15.0 to 7.16.0

ddependabot[bot] committed 4 years ago
Unverified
e08a5d7b20b54adfae20d5c59cae063656529b3a

Bump node-notifier from 8.0.0 to 8.0.1

ddependabot[bot] committed 4 years ago
Unverified
eb762764b711e845372574227d35e1ae999b2e7e

dependabot: increase if necessary

jjfgreffier committed 4 years ago

README

The README file for this repository.

🎭 Playwright relative selector

npm version Actions Status Code Coverage

Selecting elements based on layout is native to Playwright since 1.8.0

await page.click(':text("Sign In"):right-of(#home)');

Please refer to Playwright's documentation https://playwright.dev/docs/selectors#selecting-elements-based-on-layout


Click to see depreciated documentation

Playwright helper to locate elements relative to others

Usage

npm install --save-dev playwright-relative-selector

Once installed, you can require this package in a Node.js script and use it with Playwright.

const relativeSelector = require('playwright-relative-selector');

const clickMeElement = await relativeSelector(page, 'text="Sign In" toRightOf css=#home');
await clickMeElement.click();

Selectors

Available selectors:

  • above
  • below
  • toLeftOf
  • toRightOf
  • near

An element is considered relative to another if the distance between the two is of 30px or less.

Examples

First example

This code snippet sets a page with three buttons and clicks on the 'Click me' element on the right of 'Middle'

const { firefox } = require('playwright');
const relativeSelector = require('playwright-relative-selector');

(async () => {
  const browser = await firefox.launch({ headless: false });
  const context = await browser.newContext();
  const page = await context.newPage();
  await page.setContent(`
    <div>
      <button>Click me</button><span>Middle</span><button>Click me</button>
    </div>
  `);

  const clickMeElement = await relativeSelector(page, 'text="Click me" toRightOf text="Middle"');
  await clickMeElement.click();

  await browser.close();
})();