Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Locating elements via Selenium
#1
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.
Reply
#2
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
Reply
#3
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Selenium cant get elements from HTML(Rookie) Troop 1 2,181 Mar-31-2020, 03:37 AM
Last Post: Larz60+
  Selenium Random Elements Id and class AgileAVS 1 3,760 Mar-01-2020, 12:31 PM
Last Post: metulburr
  Selenium locating an element. JokerTux 3 2,718 Dec-28-2019, 08:50 AM
Last Post: snippsat
  Getting error when accessing elements in a modal window of an webpage using selenium sumandas89 3 8,697 Jul-13-2018, 10:44 AM
Last Post: mlieqo
  locating element with selenium after login sumandas89 1 3,660 Jan-15-2018, 02:40 PM
Last Post: metulburr
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 3,649 Nov-03-2017, 08:41 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020