如何在类python中创建所有可见元素的列表 [英] How to create a list of all visible elements in a class python

查看:102
本文介绍了如何在类python中创建所有可见元素的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python 3.x Selenium WebDriver,并且正在进行for循环以遍历页面中的所有元素,并限制了类中元素的长度,然后打印了迭代次数,但它显示了所有隐藏元素如何仅获取页面中的可见元素.

I am using python 3.x Selenium WebDriver and I am making a for loop to go all through the elements of the page with limit the length of the elements in the class and then print number of iteration but it gets all visible and hidden elements how to get only visible element in the page.

要从我正在使用的类中获取所有元素

To get all elements from the class I am using

showMore = driver.find_elements_by_class_name('getPhotos')

推荐答案

您可以获取所有元素(可见和不可见)的列表,并将其过滤为仅可见的元素.有几种方法可以做到这一点.这是一种.

You can take the list of all elements (visible and invisible) and filter it down to only those that are visible. There are several ways to do this... here is one.

showMore = driver.find_elements_by_class_name('getPhotos')
onlyVisible = filter(lambda x: x.is_displayed(), showMore)

这篇关于如何在类python中创建所有可见元素的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆