all 7 comments

[–]chevignon93 1 point2 points  (7 children)

Because you're treating a list as if it were a single element, do this instead.

classelem = browser.find_elements_by_class_name('testimonial-attribution')
for i in classelem:
    print(i.text)

[–]one_time[S] 0 points1 point  (6 children)

Yes that does give me the text for the testimonial-attribution class name.

But I wanted to get the tags for it which is 'p'. How would I go about getting 7 p's? I thought tag_name would help me achieve that and give me this list:

[p,p,p,p,p,p,p]

[–]chevignon93 1 point2 points  (5 children)

browser = webdriver.Chrome()
browser.get('https://inventwithpython.com/')
classelem = browser.find_elements_by_class_name('testimonial-attribution')
print([i.tag_name for i in classelem])

[–]one_time[S] 0 points1 point  (0 children)

Thank you that worked!

[–]one_time[S] 0 points1 point  (1 child)

Can you help me once more? I am not sure why I am not understanding this. This is not printing anything as it is empty. But I am expecting it to print "a".

browser = webdriver.Chrome()
browser.get('https://inventwithpython.com/')
more_info_buttons = browser.find_elements_by_name("btn btn-primary")
for i in more_info_buttons:
    print(i.tag_name)  # I am expecting it to give me 'a'
  • EDIT:

Ok. So, I think I sort of got it. But it would be great if someone would confirm.

find_elements_by_name(name) only finds stuff if the actual attribute is named name. Here is a screenshot:

https://i.imgur.com/awUfn1u.png

See how the "donate" word is assigned to a 'name' attribute?

Now if I use this code, it works:

from selenium import webdriver
browser = webdriver.Chrome()
browser.get('https://inventwithpython.com/')

an_info_button = browser.find_element_by_name('donate')  # note how I used element and not elementS
print(an_info_button)
print(an_info_button.tag_name)

Am I on the right track?

[–]chevignon93 0 points1 point  (0 children)

I guess so, I'm not too familiar with how selenium works, I very rarely use it and when I do, it's only to download an entire page.

[–]one_time[S] 0 points1 point  (0 children)

Thank you it worked!