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,17 +52,25 @@ export function getQueryHandlerAndSelector(selector: string): {
|
||||
}
|
||||
}
|
||||
}
|
||||
const [pSelector, isPureCSS, hasPseudoClasses] = parsePSelectors(selector);
|
||||
if (isPureCSS) {
|
||||
try {
|
||||
const [pSelector, isPureCSS, hasPseudoClasses] = parsePSelectors(selector);
|
||||
if (isPureCSS) {
|
||||
return {
|
||||
updatedSelector: selector,
|
||||
selectorHasPseudoClasses: hasPseudoClasses,
|
||||
QueryHandler: CSSQueryHandler,
|
||||
};
|
||||
}
|
||||
return {
|
||||
updatedSelector: JSON.stringify(pSelector),
|
||||
selectorHasPseudoClasses: hasPseudoClasses,
|
||||
QueryHandler: PQueryHandler,
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
updatedSelector: selector,
|
||||
selectorHasPseudoClasses: hasPseudoClasses,
|
||||
selectorHasPseudoClasses: false,
|
||||
QueryHandler: CSSQueryHandler,
|
||||
};
|
||||
}
|
||||
return {
|
||||
updatedSelector: JSON.stringify(pSelector),
|
||||
selectorHasPseudoClasses: hasPseudoClasses,
|
||||
QueryHandler: PQueryHandler,
|
||||
};
|
||||
}
|
||||
|
@ -358,12 +358,22 @@ describe('Query handler tests', function () {
|
||||
})
|
||||
).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
|
||||
// cases from bug reports.
|
||||
for (const selector of [
|
||||
'.user_row[data-user-id="\\38 "]:not(.deactivated_user)',
|
||||
`input[value='Search']:not([class='hidden'])`,
|
||||
`[data-test-id^="test-"]:not([data-test-id^="test-foo"])`,
|
||||
`& > table`,
|
||||
]) {
|
||||
await page.$$(selector);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user