Skip to content

Commit 4758ef4

Browse files
author
George Griffiths
committed
custome engine experiment
1 parent ff4f956 commit 4758ef4

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

examples/playwright/custom-engine.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { selectorEngine } = require("query-selector-shadow-dom/plugins/playwright");
1+
const { selectorEngine } = require("../../plugins/playwright");
22
const playwright = require('playwright')
33

44
const main = async () => {
@@ -10,7 +10,9 @@ const main = async () => {
1010

1111
await page.goto('chrome://downloads')
1212

13-
await page.waitForSelector('shadow=#no-downloads span', {timeout: 3000})
13+
const element = await page.waitForSelector('.//div', {timeout: 3000})
14+
const span = await element.$$("div > .illustration + span")
15+
console.log(span)
1416
await new Promise(resolve => setTimeout(resolve, 3000))
1517

1618
await page.close()

examples/puppeteer/clicking-elements.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
const puppeteer = require('puppeteer');
2-
const path = require('path');
3-
const fs = require('fs');
2+
const { queryHandler } = require("../../plugins/puppeteer");
43
(async () => {
54
try {
5+
puppeteer.__experimental_registerCustomQueryHandler('shadow', queryHandler);
66
const browser = await puppeteer.launch({
7-
headless: false
7+
headless: false,
8+
devtools: true
89
})
910
const page = await browser.newPage()
10-
await page.goto('http://127.0.0.1:5500/test/')
11-
12-
// makes the library available in evaluate functions which run within the browser context
13-
await page.addScriptTag({
14-
path: path.join(__dirname, 'node_modules/query-selector-shadow-dom/dist/querySelectorShadowDom.js')
15-
});
11+
await page.goto('http://127.0.0.1:5501/test/')
1612

1713

1814
// ensure btn exists and return it
19-
const btn = (await page.waitForFunction(() => {
20-
const btn = querySelectorShadowDom.querySelectorDeep(".btn-in-shadow-dom");
21-
return btn;
22-
})).asElement();
15+
const btn = await page.$("shadow/.btn-in-shadow-dom");
16+
console.log(btn);
2317
await btn.click();
2418
// check btn was clicked (this page expected btn to change text of output)
25-
const outputSpan = await page.evaluateHandle(() => querySelectorShadowDom.querySelectorDeep(".output"));
19+
const outputSpan = await page.$("shadow/.output");
2620
const text = await page.evaluate((output) => output.innerText, outputSpan);
2721
// prints the text from the output
2822
console.log(text);

plugins/puppeteer/index.js

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)