Reputation: 33792
Using playwright I am trying to do a simple login operation on a website
The steps are simple :
I can see that the selector is getting to the correct field but fails to enter the username into the input (and times out instead)
async def login(url, username, password):
async with async_playwright() as p:
browser = await p.chromium.launch(headless=False)
page = await browser.new_page()
await page.goto(url)
print(await page.title())
# Click login
await page.click('xpath=/html/body/nav[2]/div/ul/li[4]/a')
await page.pause()
# Wait for email popup
# await page.type('[placeholder="Enter your email address and hit enter"]', username)
await page.type('//input[@type="email" and not(@disabled)]', username, delay = 10) # fails here
await page.click('xpath=/html/body/app-main/app-widget/screen-layout/main/current-screen/div/screen-login/p[2]/button')
asyncio.run(login(url, username, password))
The error that I get is a timeout :
return await self.inner_send(method, params, False)
File "/Users/work/Documents/Code/venv/lib/python3.9/site-packages/playwright/_impl/_connection.py", line 63, in inner_send
result = next(iter(done)).result()
playwright._impl._api_types.TimeoutError: Timeout 30000ms exceeded.
=========================== logs ===========================
waiting for selector "//input[@type="email" and not(@disabled)]"
============================================================
This essentially means playwright was waiting for this element and no luck finding it, so it explodes after the default 30 seconds
I tried using
I also tried using selenium and strangely the behavior is the same.
The website in question: https://epaper.thehindu.com/
That particular element on the website that I am trying to type into
<input _ngcontent-ttw-c171="" fieldloginemail="" type="email" placeholder="Enter your email address and hit enter" id="email" class="sub margin-0 empty" autocorrect="off" autocapitalize="off">
The question is : why playwright cannot find this input? (Playwright Inspector can clearly see it in broad daylight)
Upvotes: 0
Views: 1958
Reputation: 4264
As @senaid already pointed out, the element you want to access is inside an iframe. So you can use the iframe locator as given in the link provided by senaid and then use it to login.
loc = await page.frameLocator('#piano-id-u4ajR').locator('#email');
await loc.type("username");
Upvotes: 2
Reputation: 802
Check for if any iFrame is there. If iframe is not there then you can try this.
const element = page.locator("//input[@type="email" and not(@disabled)]").first();
await element.focus();
await element.click();
await page.locator("//input[@type="email" and not(@disabled)]").first().fill(textTobeEntered)
Upvotes: 0
Reputation: 650
That whole element is iFrame. Get that iFrame first then type. https://playwright.dev/docs/release-notes#frame-locators
Upvotes: 2