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

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

  •  
  •   zmqking · 2018-07-12 17:39:48 +08:00 · 4854 次点击
    这是一个创建于 2086 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    2 条回复    2018-07-16 09:29:10 +08:00
    careofzm
        1
    careofzm  
       2018-07-13 12:16:22 +08:00   ❤️ 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
       2018-07-16 09:29:10 +08:00
    @careofzm 谢谢!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3266 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 11:53 · PVG 19:53 · LAX 04:53 · JFK 07:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.