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