AttributeError: 'NoneType' object has no attribute 'inner_html'

Viewed 235

I'm using Playwright Python, but having this error in a certain piece of my code, I was wondering if it's a bug or I'm doing something wrong. Here's the code:

table = await page.query_selector("#grvPedidos")
time.sleep(3)
print(await table.inner_html())

Result:

AttributeError: 'NoneType' object has no attribute 'inner_html'

But I'm absolutely sure that this table exists and has content, if I go through Selenium it recognizes normal, I want to know what's going wrong.

1 Answers

I know you said you're sure the element exists but I would still suggest using page.wait_for_selector() instead because I've run into a few situations where the element simply wasn't ready yet even though it seemed like it should be:

table = page.wait_for_selector('#grvPedidos')
print(table.inner_html())

Note that I'm using synchronous Playwright.

Related