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

2018-07-12 17:39:48 +08:00
 zmqking

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

4874 次点击
所在节点    Python
2 条回复
careofzm
2018-07-13 12:16:22 +08:00
试试这个
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
2018-07-16 09:29:10 +08:00
@careofzm 谢谢!

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/470298

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX