from playwright.sync_api import sync_playwright
playwright = sync_playwright().start()
browser = playwright.chromium.launch()
page = browser.new_page()
page.goto('https://news.ycombinator.com/login?goto=news')
page.get_by_label('username').fill('mherrmann')
# playwright._impl._errors.TimeoutError: Locator.fill: Timeout 30000ms exceeded.
I suspect Playwright expects there to be a <label> for an <input> element.It does work with Helium:
from helium import *
start_chrome('https://news.ycombinator.com/login?goto=news')
write('mherrmann', into='username')
The two scripts are equivalent, except Helium's works and is half as long. <table border="0"><tr><td>username:</td><td><input type="text" name="acct" size="20" autocorrect="off" spellcheck="false" autocapitalize="off" autofocus="true"></td></tr><tr><td>password:</td><td><input type="password" name="pw" size="20"></td></tr></table><br>
as they only put text username not <label> and the input is named "acct" (without even the common decency to include autocomplete=username)So if your script really did write that string into a what it thinks is 'username' then that's arguably one more thing to debug when its wizardry goes awry in some unknown way
So if your script really did write that string into a what it thinks is 'username' then that's arguably one more thing to debug when its wizardry goes awry in some unknown way
I tested my script. It writes into the correct field. The logic is not hard: "Find an element to the right of the given label." If there are multiple, then Helium uses the one that's closest to the last element it interacted with. That's just how a human would do it. It works surprisingly well. In many years of using Helium, I barely recall this causing problems once.
Try it before judging. You will be surprised by how well it works.
from playwright.sync_api import sync_playwright
playwright = sync_playwright().start()
browser = playwright.chromium.launch()
page = browser.new_page()