You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Playwright Python同步API将所有<select>元素设置为指定值

如何使用Playwright Python同步API将所有元素数量,再通过nth(index)来逐个定位操作:

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page()
    page.goto("你的目标页面URL")
    
    selects_locator = page.locator("select")
    # 先拿到所有匹配元素的数量
    select_count = selects_locator.count()
    # 按索引逐个操作
    for i in range(select_count):
        selects_locator.nth(i).select_option("raw")
    
    browser.close()

额外小提示

  • 要是你的
相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.07 06:54:49