0

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 :

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.

1 Answer 1

1

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")
Sign up to request clarification or add additional context in comments.

8 Comments

Please specifiy, on if you'd like to get all HTML button elements or HTML link elements.
You can use Chrome/Firefox Plugins like XPath selector to do the job for you. They will highlight which current button/s is/are going to be affected by your query.
Thanks for the reply !! yes it works. However the find_element_by_xpath has been deprecated. So i used find_elements(By.XPATH,"//button"). It lists the following ProductsCDCR, Products, SolutionsCDCR, Support, SupportCDCR, LearnCDCR, Partners, fwt-nav-button...However wondering what we can do to also obtain the 'Log in' button name?
how to obtain HTML link elements as well?
As we speaking. If you need to get a specific attribute from the buttons you can put a .get_attribute('id') behind your find_elements(By.XPATH,"//button") . If you're simply searching for the inner name do .get_attribute('innerHTML') .
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.