mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: ensure selector parser falls back to CSS (#12585)
This commit is contained in:
parent
772e088f9c
commit
80783fef5a
@ -52,6 +52,7 @@ export function getQueryHandlerAndSelector(selector: string): {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
const [pSelector, isPureCSS, hasPseudoClasses] = parsePSelectors(selector);
|
const [pSelector, isPureCSS, hasPseudoClasses] = parsePSelectors(selector);
|
||||||
if (isPureCSS) {
|
if (isPureCSS) {
|
||||||
return {
|
return {
|
||||||
@ -65,4 +66,11 @@ export function getQueryHandlerAndSelector(selector: string): {
|
|||||||
selectorHasPseudoClasses: hasPseudoClasses,
|
selectorHasPseudoClasses: hasPseudoClasses,
|
||||||
QueryHandler: PQueryHandler,
|
QueryHandler: PQueryHandler,
|
||||||
};
|
};
|
||||||
|
} catch {
|
||||||
|
return {
|
||||||
|
updatedSelector: selector,
|
||||||
|
selectorHasPseudoClasses: false,
|
||||||
|
QueryHandler: CSSQueryHandler,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -358,12 +358,22 @@ describe('Query handler tests', function () {
|
|||||||
})
|
})
|
||||||
).toBeTruthy();
|
).toBeTruthy();
|
||||||
|
|
||||||
|
using root = await page.$('div');
|
||||||
|
using button = await root!.$('& > button');
|
||||||
|
assert(button, 'Could not find element');
|
||||||
|
expect(
|
||||||
|
await button.evaluate(element => {
|
||||||
|
return element.id === 'b';
|
||||||
|
})
|
||||||
|
).toBeTruthy();
|
||||||
|
|
||||||
// Should parse more complex CSS selectors. Listing a few problematic
|
// Should parse more complex CSS selectors. Listing a few problematic
|
||||||
// cases from bug reports.
|
// cases from bug reports.
|
||||||
for (const selector of [
|
for (const selector of [
|
||||||
'.user_row[data-user-id="\\38 "]:not(.deactivated_user)',
|
'.user_row[data-user-id="\\38 "]:not(.deactivated_user)',
|
||||||
`input[value='Search']:not([class='hidden'])`,
|
`input[value='Search']:not([class='hidden'])`,
|
||||||
`[data-test-id^="test-"]:not([data-test-id^="test-foo"])`,
|
`[data-test-id^="test-"]:not([data-test-id^="test-foo"])`,
|
||||||
|
`& > table`,
|
||||||
]) {
|
]) {
|
||||||
await page.$$(selector);
|
await page.$$(selector);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user