-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[REGRESSION]: Text selector changed behavior #5634
Comments
I have noticed that text selectors have been broken in 1.9.0 and 1.9.1
My selector I can't seem to downgrade to 1.8.1 as my ci pipeline uses |
Is there a workaround for this? |
Use a regex selector instead - |
@ychaudhari Do you have a repro script by any chance? The following works for me as expected with 1.9.1: await page.setContent(`
<h2>
<span>Title:</span>
<span>text</span>
</h2>`);
console.log(await page.$eval('"text"', e => e.outerHTML)); // prints "<span>text</span>" |
|
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch({ headless: false, slowMo: 1000 });
const page = await browser.newPage();
await page.setContent(`
<div>
<h1>MyApp Login</h1>
<form action="#">
<div>
<div><button type="button">Login</button></div>
<div ><a href="/">My Login</a></div>
</div>
</form>
</div>
`);
await page.click('"Login"');
console.log(await page.$eval('"Login"', e => e.outerHTML));
await browser.close();
})(); @dgozman , In above code if you turn debug logs on pw:api <= page.setContent succeeded +1s
pw:api => page.click started +3ms
pw:api waiting for selector ""Login"" +4ms
pw:api selector resolved to visible <h1>MyApp Login</h1> +15ms Note |
@ychaudhari Thank you for the snippet! That's right, |
Thanks @dgozman for the reply, The documentation seems to be updated and it says that double quotes match is case-sensitive. But now, it does not specify if it is a full-string match. If it is updated to accept partial match then, what is the logic of matching this case-sensitive string? Personally It is confusing to me that PS: As per https://playwright.dev/docs/selectors/#prioritize-user-facing-attributes I would like to use only user facing text attribute - i.e. Here is my view on current state: const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch({ headless: false, slowMo: 1000 });
const page = await browser.newPage();
await page.setContent(`
<div>
<h1>MyApp Login</h1>
<form action="#">
<div>
<div><button type="button">Login</button></div>
<div ><a href="/">My Login</a></div>
</div>
</form>
</div>
`);
// full-string, case-sensitive -- Expected: <button type="button">Login</button> ; Actual: <h1>MyApp Login</h1>
console.log(await page.$eval('"Login"', (e) => e.outerHTML));
// full-string, case-sensitive -- Expected: <button type="button">Login</button> ; Actual: <h1>MyApp Login</h1>
console.log(await page.$eval('text="Login"', (e) => e.outerHTML));
// partial-text, case-insensitive -- OK (prints <h1>MyApp Login</h1>)
console.log(await page.$eval('text=lOgIn', (e) => e.outerHTML));
// regex, full-string -- OK (prints <button type="button">Login</button>)
console.log(await page.$eval('text=/^Login$/', (e) => e.outerHTML));
// regex, partial-text, case-sensitive -- OK (prints <h1>MyApp Login</h1>)
console.log(await page.$eval('text=/Login/', (e) => e.outerHTML));
await browser.close();
})(); |
This is fixed in playwright v1.9.2. |
Context:
Describe the bug
As per the fix #5603 and the comment - #5603 (comment)
For
<div>text1<span>child node</span>text2</div>
In v1.8.0 -
text="child"
did not select<span>child node</span>
But it does select it in v1.9.1.
The text was updated successfully, but these errors were encountered: