1

我在 Playwright 中收到错误消息,

playwright._impl._api_types.Error: Error: failed to find element matching selector "//*[@id='rc-tabs-1-panel-apikey']/div/span/input"

我什至也尝试过更改选择器,但似乎选择器或其他东西有问题。请告诉我

这是我的代码

def test_run(playwright):
browser = playwright.chromium.launch(headless=False)
context = browser.new_context()
# Open new page
page = context.new_page()
page.goto("website url", wait_until="networkidle")
# Click [data-testid="username"]
page.click("[data-testid=\"username\"]")
# Fill [data-testid="username"]
page.fill("[data-testid=\"username\"]", "abc")
# Click [data-testid="password"]
page.click("[data-testid=\"password\"]")
# Fill [data-testid="password"]
page.fill("[data-testid=\"password\"]", "abc")
# Click [data-testid="loginBtn"]
with page.expect_navigation():
    page.click("[data-testid=\"loginBtn\"]")
# Click on Avatar
page.click("[data-testid=\"avatarContainer\"]")
# Click [data-testid="dropdownSettingsOption"]
page.click("[data-testid=\"dropdownSettingsOption\"]")
time.sleep(2)
# Click text=API Key
page.click("text=API Key")
# Click button:has-text("Regenerate API Key")
time.sleep(2)
page.click("button:has-text(\"Regenerate API Key\")")
time.sleep(2)
# p1 = str(page.text_content("xpath=//*[@id='rc-tabs-1-panel-apikey']/div/span/input"))
p1 = str(page.eval_on_selector("//*[@id='rc-tabs-1-panel-apikey']/div/span/input", "e => e.value"))
print(p1)
context.close()
browser.close()
4

0 回答 0