目前 playwright- Python 还是不完善

177 天前
 hanssx

今天发现一个 BUG ,主要是开启调试的情况下,运行完会导致浏览器 crash ,插件全部 crash (和插件本身无关),相关 issue: https://github.com/microsoft/playwright-python/issues/2160

我这边目前 100%复现,代码很简单,我贴一个,有兴趣的可以复现一下。


"C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-address=0.0.0.0 --remote-debugging-port=2333 --new-window https://www.google.com

playwright 代码

from playwright.sync_api import Playwright, sync_playwright, expect


def run(playwright: Playwright) -> None:
    browser = playwright.chromium.connect_over_cdp('http://127.0.0.1:2333')
    context = browser.contexts[0]
    # context.tracing.start(screenshots=True, snapshots=True, sources=True)
    page = context.pages[0]

    page.goto("https://www.baidu.com/")

    # context.tracing.stop(path = "trace.zip")
    # page.close()  # 加上 page.close()可以解决,但是会关闭网页啊,这没法继续后面的操作了。
    # context.close()
    # browser.close()



with sync_playwright() as playwright:
    run(playwright)



selenium 代码

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

chrome_service = Service('./chromedriver.exe')
chrome_options = Options()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:2333")

driver = webdriver.Chrome(service=chrome_service, options=chrome_options)
driver.get('https://www.baidu.com/')

856 次点击
所在节点    Python
1 条回复
hanssx
79 天前
今天发现 playwright 有头定位元素是根据前端视窗定位的?而不是根据前端源码?当我定位某个页面元素时,虽然它存在于前端源码中,但在当前分辨率下并没有出现在屏幕上,比如说有一个水平的滑动窗口,可以通过向左和向右的按钮来控制窗口中显示不同的内容,当前没有显示的话, 这种情况下定位会导致视口上下晃动,直到发生 timeout 错误。

相关 issue: https://github.com/microsoft/playwright/issues/21784

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/992175

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX