[英]How to find the total number of links in webpage using selenium python
I already tried in Java 我已经尝试过用Java
int elementsCount = allElements.size();
.size() are used in Java .size()在Java中使用
Is there any options in Python, Rather than using FORLOOP. Python中有任何选项,而不是使用FORLOOP。
You can use the len()
in Python 您可以在Python中使用
len()
allElements = driver.find_elements_by_tag_name("a")
elementsCount = len(allElements)
print(elementsCount)
You should use find_elements_by_tag_name
this gives you a list of all the elements with a
tag. 您应该使用
find_elements_by_tag_name
这将为您提供a
标签的所有元素的列表。
if you use find_element_by_tag_name
you just get the first one. 如果使用
find_element_by_tag_name
,则只会得到第一个。
Like this: 像这样:
total = driver.find_elements_by_tag_name("a")
print(len(total))
Hope this helps you! 希望这对您有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.