Python Forum

Full Version: Locating elements via Selenium
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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:
Output:
nice-name
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