-
Notifications
You must be signed in to change notification settings - Fork 105
Closed as not planned
Closed as not planned
[BUG] innerHTML and getAttribute tests fail because they are no longer atomic when using Patchright#145
Bug
Copy link
Labels
bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is neededwontfixThis will not be worked onThis will not be worked on
Description
System info
- Playwright Version: [v1.56]
- Operating System: [Windows 11]
- Browser: [Chromium/Chrome]
- Other info: Issue tested in .NET and Python. This is a test from elementhandle-convenience.spec.ts -> innerHTML should be atomic / getAttribute should be atomic
Source code
Test file (self-contained)
import asyncio
from patchright.async_api import async_playwright
#from playwright.async_api import async_playwright
async def main():
async with async_playwright() as p:
create_dummy_selector = """({
create(root, target) { },
query(root, selector) {
const result = root.querySelector(selector);
if (result)
Promise.resolve().then(() => result.textContent = 'modified');
return result;
},
queryAll(root, selector) {
const result = Array.from(root.querySelectorAll(selector));
for (const e of result)
Promise.resolve().then(() => e.textContent = 'modified');
return result;
}
})"""
await p.selectors.register("innerHtml", create_dummy_selector, content_script=False)
browser = await p.chromium.launch(
channel="chrome",
headless=False
)
context = await browser.new_context(viewport=None)
page = await context.new_page()
await page.set_content("<div>Hello</div>")
inner = await page.inner_html("innerHtml=div")
evaluate = await page.evaluate("() => document.querySelector('div').textContent")
print(f"text content via inner HTML = {inner}")
print(f"text content via evaluate = {evaluate}")
await browser.close()
asyncio.run(main())Steps
- [Run the test]
Expected
Without patching the driver you get the following output:
text content via inner HTML = Hello
text content via evaluate = modifiedActual
After patching the driver you get the following output:
text content via inner HTML = modified
text content via evaluate = modifiedThis violates the expectation that innerHTML should be atomic. There is a similar failing test to ensure that getAttribute is also atomic.
Perhaps this just needs to be documented that when using Patchright modifications to the HTML actually take effect (which to be honest I actually thought was the case).
Reactions are currently unavailable
Metadata
Metadata
Labels
bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is neededwontfixThis will not be worked onThis will not be worked on