Locating elements via Selenium - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Locating elements via Selenium (/thread-30045.html) |
Locating elements via Selenium - peterjv26 - Oct-01-2020 Hi, Below is an extract from an html page I was working with <span> <span class="nice-name"> NIFTY OCT 11200 CE </span> </span> I have some code extract like below(Did not put python tags as I am not attaching complete code) browser = webdriver.Chrome(executable_path=r"C:\Users\Admin\Downloads\chromedriver_win32\chromedriver.exe",options=options) itm = browser.find_elements_by_class_name('nice-name') print(itm.text) print(itm.get_attribute('tag')) For the print statements I am getting output as below NIFTY OCT 11200 CE None Instead of None for the tag, I was expecting it to print 'span'. How can I get the tag of the element printed? I was trying to do this to debug some code. Please help. RE: Locating elements via Selenium - mlieqo - Oct-01-2020 If you want the tag name: print(itm.tag_name) get_attribute from docs - Quote:Gets the given attribute or property of the element.meaning that if you do something like: print(itm.get_attribute('class'))the output would be:
RE: Locating elements via Selenium - peterjv26 - Oct-02-2020 Thanks mlieqo. itm.tag_name worked. Is there a link to any "complete reference" of selenium and BeautifulSoup methods/attributes etc. The documentation I am finding searching google are giving specific examples and not a complete reference |