Search code examples
pythonplaywrightplaywright-python

Playwright doesn't find dynamic element


I'm trying to login on buff.163.com. Playwright does click on the Login button but it seems like it can't find the login with password hyperlink. My current code looks like this:

from playwright.sync_api import sync_playwright


with sync_playwright() as p:
    browser = p.chromium.launch(headless=False, slow_mo=50)
    page = browser.new_page()
    page.goto("https://buff.163.com/market/csgo#tab=selling&page_num=1")
    page.locator("xpath=/html/body/div[1]/div/div[3]/ul/li/a").click()
    a_locator = page.locator('a:has-text("Login with password")').click
    page.pause()

It should click on the hyperlink.


Solution

  • The problem is that button is inside an iframe.

    enter image description here

    You could do something like this:

    page.frameLocator('iframe').locator('a:has-text("Login with password")').click()