问题
Is there any method for me to get the text "ABCD" as below HTML? I just know get the emement , but have no idea about to get its text.
element1= find_element_by_xpath("//caption/em")
Then how can I get "ABCD", is there any method like gettext()?
<table class='1'>
<caption>
<em> ABCD </em>
</caption>
</table>
回答1:
Access the text using text
attribute:
>>> element1.text
u'ABCD'
回答2:
element1= find_element_by_xpath("//caption/em")
element1.get_attribute('innerHTML')
And I found Beautiful Soup will be more better to get text.
来源:https://stackoverflow.com/questions/17613439/how-to-get-text-from-em-by-python-webdriver