尝试使用剧作家选择电子邮件字段

发布于 2025-02-06 16:47:19 字数 2197 浏览 2 评论 0原文

我正在尝试在网站上进行简单的登录

  • 操作
  • 使用

剧作家, 输入中的用户名(而不是时代)

”


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))

我得到的错误是超时:

   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)]"
============================================================

这本质上意味着剧作家正在等待此元素,没有运气找到它,因此在30秒后爆炸了

我尝试使用

  • 不同的XPATHS
  • CSS选择器
  • 文本选择器

也尝试使用Selenium,奇怪的是行为是相同的。

有问题的网站: https://epaper.thehindu.com/

我网站上的特定元素试图输入

<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">

问题的是:为什么剧作家找不到此输入? (剧作家检查员可以清楚地看到它在光天化日之下)

Using playwright I am trying to do a simple login operation on a website

The steps are simple :

  • click on a Login button
  • Try to enter an email (Playwrights fails here)

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)

Playwright inpspector screenshot


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

  • different xpaths
  • CSS selectors
  • Text selectors

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

面如桃花 2025-02-13 16:47:19

That whole element is iFrame. Get that iFrame first then type.
https://playwright.dev/docs/release-notes#frame-locators

请叫√我孤独 2025-02-13 16:47:19

正如@senaid已经指出的那样,您要访问的元素在iframe内部。因此,您可以使用Senaid提供的链接中给出的IFRAME定位器,然后使用它进行登录。

loc = await page.frameLocator('#piano-id-u4ajR').locator('#email');
await loc.type("username");

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");
稀香 2025-02-13 16:47:19

检查是否有iframe。如果没有iframe,则可以尝试。

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)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文