V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
0clickjacking0
V2EX  ›  Python

关于 playwright Python 通过 html 属性 name 选择元素的一些问题

  •  
  •   0clickjacking0 · 2022-08-01 17:28:25 +08:00 · 2149 次点击
    这是一个创建于 605 天前的主题,其中的信息可能已经有所发展或是发生改变。

    遇到一个场景,如下,在官方文档中:https://playwright.dev/python/docs/selectors ,我并没有找到如何根据元素 name 进行定位,这样的话,我该如何选择第一个 name 是 Test1 的 select ,这里不考虑 xpath 和 css ,因为是有一个 input 控制个数,如果我输入 1 ,那么只有一个 Test1 ;如果我输入 3 ,那么就有 Test1 、Test2 、Test3

    <select name="Test1">
    	<option selected="selected" value="">hello</option>
    </select>
    
    <select name="Test2">
    	<option selected="selected" value="">hello2</option>
    </select>
    
    6 条回复    2022-08-21 11:42:52 +08:00
    shadeofgod
        1
    shadeofgod  
       2022-08-01 17:35:24 +08:00
    不是写了能用 css selector 吗?

    page.locator('select[name="Test1"]').click()
    0clickjacking0
        2
    0clickjacking0  
    OP
       2022-08-01 17:58:30 +08:00
    @shadeofgod 谢谢谢谢!没仔细看
    BunnyEatingGrass
        3
    BunnyEatingGrass  
       2022-08-09 09:54:07 +08:00
    Playwright 好用么?
    automation2022
        4
    automation2022  
       2022-08-12 19:14:00 +08:00
    @BunnyEatingGrass 比 selenium 好用, 用的 CDP 方式,性能也更快,支持 context 很不错,就是只支持 web 的,没有桌面端的自动化
    BunnyEatingGrass
        5
    BunnyEatingGrass  
       2022-08-12 19:21:14 +08:00
    谢谢,正好最近也想试试 Playwright,桌面软件自动化你是用的 autoit 吗?
    automation2022
        6
    automation2022  
       2022-08-21 11:42:52 +08:00
    桌面用的 clicknium ,也支持 web 的,并且支持用户浏览器,跟 selenium 的 webdriver ,playwright 的 cdp 都不一样,他们都是调试模式,clicknium 可以支持用户的浏览器,包括已经打开的浏览器
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   943 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 21:30 · PVG 05:30 · LAX 14:30 · JFK 17:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.