How to get parent of parent's element in webdriverIO?

Viewed 392

I am running tests for iPhone safari on browser stack. But click command is not working for iPhone safari on browser stack Selector seems to find an element correctly, but click does nothing and no error,no action ,just silently not executing click.

Same test running perfectly with android device. This is issue with dom structure and I wants to click on parent of parent's element.

2 Answers

I have tried below code snippet and worked for me.

const element:WebdriverIO.Element = $('selctor');
let parentEle = element.$('..').$('..');

Should be possible with xpaths using the xpath axes, specially ancestor

<div class="one">
  <div class="two">
    <input>
  </div>
</div>

To find the parent elements of input you could use an xpath like

browser.$('//input//ancestor::div[1]') //finds div with class=two
browser.$('//input//ancestor::div[2]') //finds div with class=one

Sounds like you need

browser.$('//input//ancestor::div[2]') //finds div with class=one
Related