Given a (python) selenium WebElement can I get the innerText?

Here is a more simple approach:

element = driver.find_element_by_class_name('theelementclass')
text = element.get_attribute('innerText')

So you can do similar stuff with 'outerHTML', 'href', 'src' etc. with get_attribute() method.


You can pass webelement to js code

element = driver.find_element_by_css_selector('.theelementclass')
inner_text= driver.execute_script("return arguments[0].innerText;", element)

innerText is specific to IE. If you want a cross-platform field, use textContent:

driver.execute_script("return arguments[0].textContent", element)

element is an already obtained WebElement.

By the way, you said you tried this at the console:

$('.theelementclass').text

It won't work because .text is a function. It has to be called.