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

前端 未结 2 1006
一生所求
一生所求 2021-02-04 04:10

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()
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-04 04:41

    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
    

提交回复
热议问题