python - Selenium - cant get text from span element -


i'm confused getting text using selenium.

there span tags text inside them. when search them using driver.find_element_by_..., works fine.

but problem text can't got it.

the span tag found because can't use .get_attribute('outerhtml') command , can see this:

<span class="branding">thrivinghealthy</span> 

but if change .get_attribute('outerhtml') .text returns empty text not correct can see above.

here example (outputs pieces of dictionary):

display_site = element.find_element_by_css_selector('span.branding').get_attribute('outerhtml') 

'display_site': u'<span class="branding">thrivinghealthy</span>'

display_site = element.find_element_by_css_selector('span.branding').text 

'display_site': u''

as can see, there text not finds it. wrong?

edit: i've found kind of workaround. i've changed .text .get_attribute('innertext')

but i'm still curious why works way?

the problem there lot of tags fetched using span.branding. when queried page using find_elements (plural), returned 20 tags. each tag seems doubled... i'm not sure why guess 1 set hidden while other visible. can tell, first of pair hidden. that's why aren't able pull text it. selenium's design not interact elements user can't interact with. that's why can element when try pull text, doesn't work. best bet pull entire set find_elements , loop through set getting text. loop through 20 , text 10 looks you'll still entire set anyway. it's weird should work.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -