(Playwright async ) How to fix :' AttributeError: 'coroutine' object has no attribute 'inner_text' '

(Playwright async ) How to fix :' AttributeError: 'coroutine' object has no attribute 'inner_text' '

我已经编写了一个异步剧作家函数,但我不知道如何使用 await 将此赋值放入我的函数中。 这是导致我出错的代码行:

country = await feedback.query_selector('[class="user-country"]').inner_text()

这是我在控制台中得到的错误:

    country = await feedback.query_selector('[class="user-country"]').inner_text()
AttributeError: 'coroutine' object has no attribute 'inner_text'
sys:1: RuntimeWarning: coroutine 'ElementHandle.query_selector' was never awaited

如果您能提供帮助,我将不胜感激。 谢谢!

应该是:await (await feedback.query_selector('[class="user-country"]')).inner_text()。但我们不鼓励使用 ElementHandles,请参阅此处:https://playwright.dev/docs/next/locators#locator-vs-elementhandle