我在使用playwright写自动化脚本的时候,使用类封装后尝试运行我的代码,然而确保协程页面转到从未期待
class MyTestCase():
def __init__(self):
with sync_playwright() as p:
for browser_type in [p.chromium, p.firefox, p.webkit]:
browser:Browser = browser_type.launch(headless=False)
self.page:Page = browser.new_page()
class One(MyTestCase):
def run(self):
print(self.page)
self.page.goto(url)
if __name__ == '__main__':
m = One()
m.run()
D:\ProgramData\Anaconda3\envs\RongDaZhiHuiYun1.0.3\python.exe D:/Users/17600/PycharmProjects/RongDaZhiHuiYun1.0.3/Base/myTestCase.py
Traceback (most recent call last):
File "D:/Users/17600/PycharmProjects/RongDaZhiHuiYun1.0.3/Base/myTestCase.py", line 23, in <module>
m.run()
File "D:/Users/17600/PycharmProjects/RongDaZhiHuiYun1.0.3/Base/myTestCase.py", line 15, in run
self.page.goto(url)
File "D:\ProgramData\Anaconda3\envs\RongDaZhiHuiYun1.0.3\lib\site-packages\playwright\sync_api\_generated.py", line 5957, in goto
url=url, timeout=timeout, waitUntil=wait_until, referer=referer
File "D:\ProgramData\Anaconda3\envs\RongDaZhiHuiYun1.0.3\lib\site-packages\playwright\_impl\_sync_base.py", line 92, in _sync
task = self._loop.create_task(coro)
File "D:\ProgramData\Anaconda3\envs\RongDaZhiHuiYun1.0.3\lib\asyncio\base_events.py", line 402, in create_task
<Page url='about:blank'>
self._check_closed()
File "D:\ProgramData\Anaconda3\envs\RongDaZhiHuiYun1.0.3\lib\asyncio\base_events.py", line 479, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
sys:1: RuntimeWarning: coroutine 'Page.goto' was never awaited
求大神帮助
你好,我是有问必答小助手。为了技术专家团更好地为您解答问题,烦请您补充下(1)问题背景详情,(2)您想解决的具体问题,(3)问题相关代码图片或者报错信息。便于技术专家团更好地理解问题,并给出解决方案。
您可以点击问题下方的【编辑】,进行补充修改问题。