V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
Ethson
V2EX  ›  Python

Python selenium 的 WebElement 如何获取 text?

  •  
  •   Ethson · Sep 23, 2022 · 2554 views
    This topic created in 1313 days ago, the information mentioned may be changed or developed.
    browser = webdriver.Chrome()
    browser.get("")
    answers_list = browser.find_elements(By.CLASS_NAME, "List-item")
    print(answers_list[0].text)
    

    selenium version = 4.4.3

    WebElement.text 总是返回 visible text ,对于 invisible text 呢?我找了一下,没找到接口。

    有大兄弟能指教下么?谢谢了。

    4 replies    2022-09-27 14:13:28 +08:00
    smartwusir007
        1
    smartwusir007  
       Sep 23, 2022
    啥是 visible text, 啥是 invisible text ?
    lookStupiToForce
        2
    lookStupiToForce  
       Sep 23, 2022
    不懂你说的 invisible text 是啥,但感觉你把 dir(answers_list[0])了之后全试一遍就行......
    Deteriorator
        3
    Deteriorator  
       Sep 24, 2022
    那你直接 get attribute 好了
    runningman
        4
    runningman  
       Sep 27, 2022
    这是个问题吗
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3705 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 52ms · UTC 00:04 · PVG 08:04 · LAX 17:04 · JFK 20:04
    ♥ Do have faith in what you're doing.