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
zmqking
0D
V2EX  ›  Python

怎样判断当前元素是否是可见状态 selenium Python

  •  
  •   zmqking · Jul 12, 2018 · 5316 views
    This topic created in 2857 days ago, the information mentioned may be changed or developed.

    我用的 selenium,然后通过 find_elements_by_css_selector 方法找到多个相同元素(但实际只显示了一个),我就想找到显示的那一个,本人刚接触 python 没几天,还望大神指教,谢谢!

    2 replies    2018-07-16 09:29:10 +08:00
    careofzm
        1
    careofzm  
       Jul 13, 2018   ❤️ 1
    试试这个
    https://stackoverflow.com/questions/15937966/in-python-selenium-how-does-one-find-the-visibility-of-an-element

    from selenium import webdriver

    driver = webdriver.Firefox()
    driver.get('http://www.google.com')
    element = driver.find_element_by_id('gbqfba') #this element is visible
    if element.is_displayed():
    print "Element found"
    else:
    print "Element not found"

    hidden_element = driver.find_element_by_name('oq') #this one is not
    if hidden_element.is_displayed():
    print "Element found"
    else:
    print "Element not found"
    zmqking
        2
    zmqking  
    OP
       Jul 16, 2018
    @careofzm 谢谢!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   951 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 21:09 · PVG 05:09 · LAX 14:09 · JFK 17:09
    ♥ Do have faith in what you're doing.