webdriverio-boneyard / v4

Deprecated code base for all WebdriverIO releases up until v4.x
MIT License
8 stars 21 forks source link

how to get ELEMENT value in Standalone Mode #12

Open christian-bromann opened 5 years ago

christian-bromann commented 5 years ago

From @jiangyd on October 29, 2018 7:25

> var webdriverio = require('webdriverio');
undefined
> var options = { desiredCapabilities: { browserName: 'chrome' } };
undefined
> var client = webdriverio.remote(options);
undefined
> client.init().url("https://csos.cloudcare.cn")
{ state: 'pending' }
> var eleobject=client.element('/html/body/div[2]/header/div[2]/a[2]/input')
undefined
> console.log(eleobject)
{ state: 'fulfilled',
  value:
   { sessionId: '95a30dc18d91b93def35e58cc5cfd405',
     status: 0,
     value:
      { ELEMENT: '0.8181596695218141-1',
        'element-6066-11e4-a52e-4f735466cecf': '0.8181596695218141-1' },
     selector: '/html/body/div[2]/header/div[2]/a[2]/input' } }
undefined
> console.log(eleobject.value.value.ELEMENT)
TypeError: Cannot read property 'value' of undefined
    at repl:1:29
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at REPLServer.defaultEval (repl.js:240:29)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at REPLServer.onLine (repl.js:442:10)
    at emitOne (events.js:121:20)
    at REPLServer.emit (events.js:211:7)
    at REPLServer.Interface._onLine (readline.js:282:10)
    at REPLServer.Interface._line (readline.js:631:8)
> client.elementIdRect(client.element('/html/body/div[2]/header/div[2]/a[2]/input').value.ELEMENT)
TypeError: Cannot read property 'ELEMENT' of undefined
    at repl:1:88
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at REPLServer.defaultEval (repl.js:240:29)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at REPLServer.onLine (repl.js:442:10)
    at emitOne (events.js:121:20)
    at REPLServer.emit (events.js:211:7)
    at REPLServer.Interface._onLine (readline.js:282:10)
    at REPLServer.Interface._line (readline.js:631:8)

Copied from original issue: webdriverio/webdriverio#3027

christian-bromann commented 5 years ago

From @erwinheitzman on October 30, 2018 17:42

This is not an issue but a question, please use our gitter channel for this.

To answer the question though, you use it like this:

webdriverio
  .remote(options)
  .init()
  .url('some-page')
  .element('#some-input')
  .setValue('some value')
  .getValue('#some-input').then(value => {
    console.log('Value was: ', value); // logs "Value was: some value"
  })
  .end()
  .catch(function(err) {
      console.log(err);
  });
christian-bromann commented 5 years ago

This can be related to the repl interprets the return value. Let's reopen.

@jiangyd note that we are working hard on the new WebdriverIO version so we can't look into fixing a bug of a version that will be deprecated soon. We are happy to accept pull requests that fix the issue.