Issue
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.
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")
Answered By - Dotolox
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.