Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to list all clickable links in a website using selenium, python?

I am new to selenium. I want to navigate to www.cisco.com and list all the clickable buttons by their names (and respective xpaths too if possible) in a list like

[‘Log in’,’Products and services’,’Solutions’,….etc. ]

I can navigate to the site using a chrome browser exe as given below :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

from selenium import webdriver
from selenium.webdriver.common.by import By
chromedriver_location = "C:\\Path\\To\\chromedriver"

driver = webdriver.Chrome(chromedriver_location)
driver.get('https://cisco.com/')

first_popup_close='//*[@id="onetrust-close-btn-container"]/button'
supposedly_front_page='//*[@id="wcq"]'
#Close the pop-up
driver.find_element("xpath", first_popup_close).click()

#If I am not wrong in selecting the XPATH..
ids = driver.find_elements(By.XPATH, supposedly_front_page)

for i in ids:
    #print i.tag_name
    print(i.get_attribute("name"))    # Does not work as expected

I even tried using find_element(By.LINK_TEXT, "Log in"),find_element(By.PARTIAL_LINK_TEXT, "Log")etc. just to find only the ‘Log in’ button (in case my front page XPATH may be wrong), but it does not return the output (empty list).
The issue is – selenium doc has vague information about such or may be I am not able to find the required info. The older posts about the same does not work mostly as lots of functions have been deprecated by now.

>Solution :

If you like to get the login button for example from this page do:

loginbtn = driver.find_element_by_xpath("//button[@id='fwt-profile-button']")

or if you’d like to get all buttons you can identify them by doing:

btns = driver.find_elements_by_xpath("//button")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading