关于playwright #python#的问题:超时后报错

代码如下


from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(headless=False)
    context = browser.new_context()
    page = context.new_page()
    list1 = ['Russian Federation','United States','Canada','Spain','France','United Kingdom','Netherlands','Israel','Brazil','Chile','Australia','Ukraine','Belarus','Japan','Thailand','Singapore','South Korea','Indonesia','Malaysia','Philippines','Vietnam','Italy','Germany','Saudi Arabia','United Arab Emirates','Poland','Turkey','Portugal']
    print(list1[0])
    page.goto("https://www.aliexpress.com/item/1005001955136541.html")
    print(page.inner_text("#root > div > div.product-main > div > div.product-info > div.product-price > div.product-price-current > span"))
    for i in list1:
        print(i)
        page.click("#root > div > div.product-main > div > div.product-info > div.product-shipping > span.product-shipping-info.black-link")
        page.click("body > div.next-overlay-wrapper.opened > div.next-overlay-inner.next-dialog-container > div > div.next-dialog-body > div > div.address > span > span > span > span.next-select-values.next-input-text-field")
        page.fill("#ae-search-select-1", i)
        page.click("body > div.next-overlay-wrapper.opened > div.next-overlay-inner.next-dialog-container > div > div.next-dialog-body > div > div.address > span > div > div > div > ul > li:nth-child(1) > div")
        with page.expect_navigation():
            page.click("body > div.next-overlay-wrapper.opened > div.next-overlay-inner.next-dialog-container > div > div.next-dialog-footer.next-align-center > button")
        print(page.inner_text("#root > div > div.product-main > div > div.product-info > div.product-price > div.product-price-current > span"))

    browser.close()

暴力通过选择器点击,

img

卡在点击apply的时候,自己点击就会继续运行,直到再次卡住。
img
没搞懂为什么会卡住。超时后报错
img

用你的这个代码跑了几次,不会卡住,也不会报错,只是偶尔不跳转,需要手动重点一下