7

I have the following element(text area). The value of this text area won't appear in the html code. But that will be displayed in webpage when page is loaded. How to get the value using selenium and python.

<textarea id="query" class="textarea" cols="37" rows="30"></textarea>

dorvak
  • 9,219
  • 4
  • 34
  • 43
chetan
  • 97
  • 1
  • 2
  • 5

2 Answers2

7

The contents of the textarea will be shown in it's value property, just like input elements. So something like (pseudo-Python)

 contents = driver.find_element_by_id('query').get_attribute('value')
Arran
  • 24,648
  • 6
  • 68
  • 78
2

one thing which you can do is capture a screenshot of that area using and extract the text later using tesseract. Got same issue as text entered is not being stored in value attribute EG:

to capture screenshot

featureElement = browser.find_element_by_xpath("//textarea//..")
featureElement.screenshot('foo.png')

#to read from image

images = cv2.imread('image_path')

convert to grayscale image

gray = cv2.cvtColor(images, cv2.COLOR_BGR2GRAY)

cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]

memory usage with image i.e. adding image to memory

filename = "{}.jpg".format(os.getpid())
cv2.imwrite(filename, gray)
text = pytesseract.image_to_string(Image.open(filename))
print(text)
ItsPrinceAk
  • 102
  • 7