Getting attributes/value from elements [Appium for iOS]

831 views
Skip to first unread message

egf...@voyagerinnovation.com

unread,
Jul 21, 2014, 4:33:46 AM7/21/14
to appium-...@googlegroups.com
Hi,

I'm trying to validate my automation cases by getting the text value of a StaticTextElement. I do this by calling the getValue/getAttribute method. My problem is that
when i try to print the result to the console, it only displays [object Object], also my condition for checking the return always return true. Can someone help me with this? Thanks!

Here's my code,

var textField = driver.waitForElementByAccessibilityId(app.oneToOne.nickNameField());
console.log(textField.getValue());
if (textField.getValue() == nickname) {
    return true;
}
return false;

sebv

unread,
Jul 21, 2014, 4:37:29 AM7/21/14
to appium-...@googlegroups.com
What programming language is that? Javascript?

egf...@voyagerinnovation.com

unread,
Jul 21, 2014, 4:41:07 AM7/21/14
to appium-...@googlegroups.com
Yes. I use javascript and run it using the mocha command.

sebv

unread,
Jul 21, 2014, 4:51:37 AM7/21/14
to appium-...@googlegroups.com
Your code need to be asynchronous, like in the web browser:

it('should work', function() {
  return driver
    .waitForElementByAccessibilityId(app.oneToOne.nickNameField()).getValue()
    .then(function(value) {
      console.log(value);
      return textField.getValue() === nickname;
    }).should.eventually.be.ok;
});

sebv

unread,
Jul 21, 2014, 4:53:25 AM7/21/14
to appium-...@googlegroups.com
Sorry this is  more correct:

it('should work', function() {
  return driver
    .waitForElementByAccessibilityId(app.oneToOne.nickNameField()).getValue()
    .then(function(value) {
      console.log(value);
      return value === nickname;
    }).should.eventually.be.ok;
});

egf...@voyagerinnovation.com

unread,
Jul 21, 2014, 5:04:28 AM7/21/14
to appium-...@googlegroups.com
I see, now it works! Thank you very much! :D 
Reply all
Reply to author
Forward
0 new messages