mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
feat(text selector): normalize spaces in lax mode (#4312)
This commit is contained in:
parent
8fed0b3319
commit
924cc9894a
@ -76,8 +76,8 @@ function createMatcher(selector: string): Matcher {
|
||||
const re = new RegExp(selector.substring(1, lastSlash), selector.substring(lastSlash + 1));
|
||||
return text => re.test(text);
|
||||
}
|
||||
selector = selector.trim().toLowerCase();
|
||||
return text => text.toLowerCase().includes(selector);
|
||||
selector = selector.trim().toLowerCase().replace(/\s+/g, ' ');
|
||||
return text => text.toLowerCase().replace(/\s+/g, ' ').includes(selector);
|
||||
}
|
||||
|
||||
// Skips <head>, <script> and <style> elements and all their children.
|
||||
|
@ -94,6 +94,16 @@ it('query', async ({page, isWebKit}) => {
|
||||
});
|
||||
expect(await page.$eval(`text=lowo`, e => e.outerHTML)).toBe('<div>helloworld</div>');
|
||||
expect(await page.$$eval(`text=lowo`, els => els.map(e => e.outerHTML).join(''))).toBe('<div>helloworld</div><span>helloworld</span>');
|
||||
|
||||
await page.setContent(`<span>Sign in</span><span>Hello\n \nworld</span>`);
|
||||
expect(await page.$eval(`text=Sign in`, e => e.outerHTML)).toBe('<span>Sign in</span>');
|
||||
expect((await page.$$(`text=Sign \tin`)).length).toBe(1);
|
||||
expect(await page.$(`text="Sign in"`)).toBe(null);
|
||||
expect((await page.$$(`text="Sign in"`)).length).toBe(0);
|
||||
expect(await page.$eval(`text=lo wo`, e => e.outerHTML)).toBe('<span>Hello\n \nworld</span>');
|
||||
expect(await page.$(`text="lo wo"`)).toBe(null);
|
||||
expect((await page.$$(`text=lo \nwo`)).length).toBe(1);
|
||||
expect((await page.$$(`text="lo wo"`)).length).toBe(0);
|
||||
});
|
||||
|
||||
it('create', async ({page}) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user