Grabbing the text from a TextView, Android, Javascript

I am trying to create a test which will verify that the text within a particular post matches to what is expected. I am using Javascript to create my test, and at this time and not sure how to extract the correct element that point directly to the actual text that exists within this element. I have tried pointing to the exact XPATH, but that has not yielded the correct information. Anyone have any experience with this?

for java we can use, hope u can convert in js

  1. driver.findElement(By.className(“android.widget.TextView”)).getText();
  2. driver.findElement(“”)).getText(); // if id is unique to this text
1 Like

Thanks for the reply. I will see if I can get that or something like it to work.

Quick update. I tried using this to grab the text, and it gave me a value of “status: pending” when I tested it with an assert statement. I’ve been trying to figure out what that could mean. Any clue??

it('should verify that Brett Favre is in the search field', function (done) {
    var brett = driver.elementByXPath(checkBrett);
    chai.assert.equal(brett, "Brett Favre", "oops, not Brett Favre!!");

Note: checkBrett is an Xpath saved as a variable. Also, I tried using the .getText() method on the chain, but it throws an error of “undefined is not a function”

Did this ever get resolved? I’m just trying to grab the TextView text value and haven’t been able to yet.


Please let me know if you guys were able to resolve this one

Inorder to extract the text element from the TextView, we can do it by using the following in javascript
textField = driver.waitForElementByXPath(‘xxxxx’);
errorText = errorField.text() ;
Please give this a try. it worked for me.