Reputation: 499
can someone, please, help, in following case:
Found element with following css selector (there is a list of charts, where only one chart has mark with "Current Day" text on top of it).
'div[id*="view-panel"] div.bar_chart g.bar_chart__now > text'
Based on that element, want to find another element (which is on found chart - its bottom), which displays name of the day (i.e "Friday"). Tried with following code:
cy.get('div[id*="view-panel"] div.bar_chart g.bar_chart__now > text').as('currentDay');
cy.get('@ccurrentDay').find('..').find('..').find('g.bar_chart__xaxis text');
Whole css selector for second element (for second code line above), looks:
'div[id*="view-panel"] div.bar_chart g.bar_chart__xaxis text'
What I tried to achieve is after first found element, go two steps back and find day name of chart bottom, but what I only get is an error:
CypressError: Timed out retrying: Expected to find element: ‘…’, but never found it.
What I am doing incorrect in above attempt to concatenate finding element? Thank you in advance
Upvotes: 0
Views: 3688
Reputation: 1427
You should use Within command
cy.get('div[id*="view-panel"] div.bar_chart g.bar_chart__now > text')
.within(()=>{
cy.get('g.bar_chart__xaxis text')
})
Upvotes: 1