fix: ensure selector parser falls back to CSS (#12585)

This commit is contained in:
Alex Rudenko 2024-06-14 11:14:33 +02:00 committed by GitHub
parent 772e088f9c
commit 80783fef5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 8 deletions

View File

@ -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,
};
}
} }

View File

@ -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);
} }