【问题标题】:Unable to access getText() method in Appium, Node.Js无法访问 Appium、Node.Js 中的 getText() 方法
【发布时间】:2019-09-14 12:07:51
【问题描述】:

我正在尝试使用 Appium 测试 android 应用程序。我想读取 textview 的值,但我无法这样做。我得到 getText() 不是函数错误。 以下是我的能力和代码:

 const webdriverio = require('webdriverio');
 const assert = require('chai').assert;

 const options = {
    capabilities: {
        platformName: 'Android',
        automationName: 'UiAutomator2',
        deviceName: 'Android',
        app: "some.apk",
        appWaitActivity: 'com.example.HomeActivity',
        autoGrantPermissions: true,
        autoAcceptAlerts: true,
        fullReset: true,
      },
       host: '0.0.0.0',
       port: 4723
   };


 describe('Start Test', function() {

     let client;
     before(async function() {
         client = await webdriverio.remote(options);
     });

     it('get text in textview', async function() {
          element = await client.findElement('id', "com.example:id/screenMsg"); // element is the textView
          assert.isNotNull(element);

          console.log(element); 

       /* In the console, I get something like this
          { 'element-6066-11e4-a52e-4f735466cecf': '96ec3f2a-7378-4920-a59f- c43a62bc7a44',
          ELEMENT: '96ec3f2a-7378-4920-a59f-c43a62bc7a44' }
          It means the textView is identified.
        */

         value = await element.getText(); // TypeError: element.getText() is not a function.

         console.log(value);
    });


});

【问题讨论】:

标签: appium webdriver-io appium-android android-uiautomator


【解决方案1】:

只需调用text() 方法获取值

const value = await element.text();

【讨论】:

    【解决方案2】:

    WebdriverIO 选项中的属性是hostname 而不是“host”。 见Options · WebdriverIO

    【讨论】:

      猜你喜欢
      • 2020-01-30
      • 1970-01-01
      • 2015-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-17
      相关资源
      最近更新 更多