How to get text from invisible element

Question:

I need to get the text of an invisible element, when I try to get it, it gives me nothing when printing it. I ensured that this element is not in a different iframe. Can any one help me?

Code for getting the element’s text:

text = self.dataBrowser.find_element('xpath', '//div[2]/table[1]/tbody/tr[2]/td[2]').text
Asked By: Omar Yacop

||

Answers:

As I understand, your element is hidden, i.e. (element is present in the DOM but not visible) and you are trying to extract its text.
For this, you may apply execute_javascript.

txt =  self.dataBrowser.find_element('xpath', '//div[2]/table[1]/tbody/tr[2]/td[2]')
x = driver.execute_script("return arguments[0].innerText", txt)
print(x)
Answered By: Anand Gautam
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.