Reputation: 117
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>
Upvotes: 9
Views: 13361
Reputation: 110
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:
featureElement = browser.find_element_by_xpath("//textarea//..")
featureElement.screenshot('foo.png')
#to read from image
images = cv2.imread('image_path')
gray = cv2.cvtColor(images, cv2.COLOR_BGR2GRAY)
cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
filename = "{}.jpg".format(os.getpid())
cv2.imwrite(filename, gray)
text = pytesseract.image_to_string(Image.open(filename))
print(text)
Upvotes: 2
Reputation: 25076
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')
Upvotes: 8