mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix(frame): fix Frame.waitFor's XPath pattern detection (#5184)
Up to now, only strings starting with '//' are considered as to XPath selectors. Unfortunately, this is too restricting. This fix allows valid XPath selectors starting with: '/', './', and even '(//*[1])'
This commit is contained in:
parent
726cb14003
commit
caa2b732fe
@ -43,6 +43,7 @@ import {
|
|||||||
} from './EvalTypes.js';
|
} from './EvalTypes.js';
|
||||||
|
|
||||||
const UTILITY_WORLD_NAME = '__puppeteer_utility_world__';
|
const UTILITY_WORLD_NAME = '__puppeteer_utility_world__';
|
||||||
|
const xPathPattern = /^\(\/\/[^\)]+\)|^\/\//;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We use symbols to prevent external parties listening to these events.
|
* We use symbols to prevent external parties listening to these events.
|
||||||
@ -1068,16 +1069,13 @@ export class Frame {
|
|||||||
options: Record<string, unknown> = {},
|
options: Record<string, unknown> = {},
|
||||||
...args: SerializableOrJSHandle[]
|
...args: SerializableOrJSHandle[]
|
||||||
): Promise<JSHandle | null> {
|
): Promise<JSHandle | null> {
|
||||||
const xPathPattern = '//';
|
|
||||||
|
|
||||||
console.warn(
|
console.warn(
|
||||||
'waitFor is deprecated and will be removed in a future release. See https://github.com/puppeteer/puppeteer/issues/6214 for details and how to migrate your code.'
|
'waitFor is deprecated and will be removed in a future release. See https://github.com/puppeteer/puppeteer/issues/6214 for details and how to migrate your code.'
|
||||||
);
|
);
|
||||||
|
|
||||||
if (helper.isString(selectorOrFunctionOrTimeout)) {
|
if (helper.isString(selectorOrFunctionOrTimeout)) {
|
||||||
const string = selectorOrFunctionOrTimeout;
|
const string = selectorOrFunctionOrTimeout;
|
||||||
if (string.startsWith(xPathPattern))
|
if (xPathPattern.test(string)) return this.waitForXPath(string, options);
|
||||||
return this.waitForXPath(string, options);
|
|
||||||
return this.waitForSelector(string, options);
|
return this.waitForSelector(string, options);
|
||||||
}
|
}
|
||||||
if (helper.isNumber(selectorOrFunctionOrTimeout))
|
if (helper.isNumber(selectorOrFunctionOrTimeout))
|
||||||
|
@ -58,6 +58,18 @@ describe('waittask specs', function () {
|
|||||||
await waitFor;
|
await waitFor;
|
||||||
expect(found).toBe(true);
|
expect(found).toBe(true);
|
||||||
});
|
});
|
||||||
|
it('should allow you to select an element with parenthesis-starting xpath', async () => {
|
||||||
|
const { page, server } = getTestState();
|
||||||
|
let found = false;
|
||||||
|
const waitFor = page.waitFor('(//img)[200]').then(() => {
|
||||||
|
found = true;
|
||||||
|
});
|
||||||
|
await page.goto(server.EMPTY_PAGE);
|
||||||
|
expect(found).toBe(false);
|
||||||
|
await page.goto(server.PREFIX + '/grid.html');
|
||||||
|
await waitFor;
|
||||||
|
expect(found).toBe(true);
|
||||||
|
});
|
||||||
it('should not allow you to select an element with single slash xpath', async () => {
|
it('should not allow you to select an element with single slash xpath', async () => {
|
||||||
const { page } = getTestState();
|
const { page } = getTestState();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user