Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python & Selenium - how do I find all element IDs on a page?

I know that I can use methods such as:

find_elements_by_tag_name() find_elements_by_id() find_elements_by_css_selector() find_elements_by_xpath() 

But what I would like to do is simply get a list of all the element IDs that exist in the page, perhaps along with the tag type they occur in.

How can I accomplish this?

like image 818
tadasajon Avatar asked Nov 27 '13 14:11

tadasajon


People also ask

What is Python used for?

Python is a computer programming language often used to build websites and software, automate tasks, and conduct data analysis. Python is a general-purpose language, meaning it can be used to create a variety of different programs and isn't specialized for any specific problems.

What is the basic language of Python?

Python has a simple syntax similar to the English language. Python has syntax that allows developers to write programs with fewer lines than some other programming languages. Python runs on an interpreter system, meaning that code can be executed as soon as it is written.

Is Python easy to learn?

Python is widely considered among the easiest programming languages for beginners to learn. If you're interested in learning a programming language, Python is a good place to start. It's also one of the most widely used.

Is Python coding good?

Python is undoubtedly considered a top programming language at the same level as JavaScript or C++, and it's one of the most used languages by businesses and enterprises. Even though it's almost 30 years old, Python is still relevant, given its ease of use, its vibrant community, and many applications.


1 Answers

from selenium import webdriver  driver = webdriver.Firefox() driver.get('http://google.com')  ids = driver.find_elements_by_xpath('//*[@id]') for ii in ids:     #print ii.tag_name     print ii.get_attribute('id')    # id name as string 
like image 193
russian_spy Avatar answered Sep 23 '22 08:09

russian_spy