Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(frame): Fix Frame.waitFor's XPath pattern detection #5184

Merged
merged 6 commits into from Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/common/FrameManager.ts
Expand Up @@ -43,6 +43,7 @@ import {
} from './EvalTypes.js';

const UTILITY_WORLD_NAME = '__puppeteer_utility_world__';
const xPathPattern = /^\(\/\/[^\)]+\)|^\/\//;

/**
* We use symbols to prevent external parties listening to these events.
Expand Down Expand Up @@ -1068,16 +1069,13 @@ export class Frame {
options: Record<string, unknown> = {},
...args: SerializableOrJSHandle[]
): Promise<JSHandle | null> {
const xPathPattern = '//';

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.'
);

if (helper.isString(selectorOrFunctionOrTimeout)) {
const string = selectorOrFunctionOrTimeout;
if (string.startsWith(xPathPattern))
return this.waitForXPath(string, options);
if (xPathPattern.test(string)) return this.waitForXPath(string, options);
return this.waitForSelector(string, options);
}
if (helper.isNumber(selectorOrFunctionOrTimeout))
Expand Down
12 changes: 12 additions & 0 deletions test/waittask.spec.ts
Expand Up @@ -58,6 +58,18 @@ describe('waittask specs', function () {
await waitFor;
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 () => {
const { page } = getTestState();

Expand Down