简体   繁体   中英

How to find the total number of links in webpage using selenium python

I already tried in Java

int elementsCount = allElements.size(); 

.size() are used in Java

Is there any options in Python, Rather than using FORLOOP.

You can use the len() in Python

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.

if you use find_element_by_tag_name you just get the first one.

Like this:

total = driver.find_elements_by_tag_name("a") 
print(len(total))

Hope this helps you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM