4

I'm using Spectron's WebdriverIO which is at version 4.7.1 in node_modules. I'm trying to getText from an element but selecting it gradually is giving me trouble.

I can "Copy -> selector" in dev tools to give me a very specific path. This works if I .element(longPath).

What isn't working for me is chaining with $ and $$ (or element / elements):

const name = await client
  .$($sideNav)
  .$$($storageItem)[0]
  .$('.StorageItem__header-info___browser-main-SideNav- span')
  .getText()

Accessing [0] gives me undefined. If I log out the resolved value of $$($storageItem), I get:

[ { ELEMENT: '0.16994195059314898-2',
    value: { ELEMENT: '0.16994195059314898-2' },
    selector: '.StorageItem__root___browser-main-SideNav-',
    index: 0 } ]

Any ideas why I can't chain as shown in the example here: http://webdriver.io/v4.7/api/utility/$.html

Many thanks.

Ilia Frenkel
  • 1,969
  • 13
  • 19
justin
  • 3,357
  • 1
  • 23
  • 28
  • I have the same problem! Did you find a solution to this problem??? – Andreas Rau Nov 25 '17 at 23:21
  • @Andreas sorry this was not an important project. I'm not sure if I worked around it or gave up as it was not important. I remember asking on the project's gitter and getting no help either. Can you see if you can select what you want some other way? – justin Nov 27 '17 at 10:19
  • I found that chaining $ and $$ is not possible. For every call the client needs to be used... Thank you anyway... – Andreas Rau Dec 07 '17 at 21:25
  • I created objects for every elements. Then I use jQuery selectors to map them like you and also mainSelector for every page. That helps tests to find object more efficient. Spectron look for child elements under mainSelector. I am sharing example script. this._selectorsMap.set(HistoryPageElements.HISTORY_RESULTS, `${this._mainSelector} .history-list-elements.history-item span `); – sayhan Oct 05 '18 at 11:33
  • @slckayhn could you elaborate? – Emily Apr 13 '22 at 21:11

0 Answers0