I want to extract text between <tag></tag>
(In my case, <tr></tr>
). so, I'm using webelement.text
self.browser = webdriver.Firefox()
table = self.browser.find_element_by_tag_name('table')
....
rows = table.find_elements_by_tag_name('tr')
print rows
for element in rows:
print type(element)
print element.text
print type(element.text)
and output is:
[<selenium.webdriver.remote.webelement.WebElement object at 0x0151E390>] # <-print rows
<class 'selenium.webdriver.remote.webelement.WebElement'> # <-print type(element)
# <-nothing from print element.text
<type 'unicode'> # <-print type(e.text)
So there is nothing from element.text, but the tags is not empty. <tr>blablabla</tr>
I got no possibility to check it on other browsers.
The problem is with <tr>
It dont see text inside <tr>blabla</tr>
:
rows = table.find_elements_by_tag_name('tr')
will be emplty.
But it see it inside <tr><td>blabla</td></tr>
:
rows = table.find_elements_by_tag_name('tr')
for element in rows:
print element.text # <-blabla
Though, it doesnt work on any nested element:
<tr><h1>blabla</h1></tr>:
rows = table.find_elements_by_tag_name('tr')
will be emplty.
The documentation on webelement.text
says just
text
Gets the text of the element.
Its just dont consider text inside
<tr>text</tr>
as the text of the<tr>
element, I suppose.