I have a website that I'm testing. It works nicely in Chrome and I can inspect the HTML with Chrome's developer tools.
When I load the page with playwright I get a correct screenshot but the HTML does not contain the content. I added a 10 sec wait just to see if that changes anything but it doesn't.
def save_html_and_screenshot():
with sync_playwright() as p:
browser = p.chromium.launch(
headless=True,
args=["--disable-gpu", "--no-zygote", "--single-process"],
)
page = browser.new_page()
page.goto("https://www.3sonsbrewingco.com/menus")
page.wait_for_load_state(state="networkidle")
page.wait_for_timeout(10000)
image_bytes_waited = page.screenshot(type="png", full_page=True)
html_waited = page.content()
open("site.png", "wb").write(image_bytes_waited)
open("site.html", "w").write(html_waited)
browser.close()
Actually, I can see the items in the devtools Elements tab but when I look at the page source in Chrome I do not see them.
So, how to get the html displayed in the "Elements" tab of Chrome's devtools?