//div[text()='#{locator.strip}']/ancestor::table/../../..//a[@class='idit-grid-btn']/i[@class='fa fa-#{var}']
I have written the following watir code for the aforementioned xpath but it's not working.
element=@browser
.div(text: locator.strip)
.preceding_sibling(tag_name: 'table')
.parent
.parent
.parent
.link(class: 'idit-grid-btn')
.i(class: "fa fa-#{var}")
Where am I going wrong?
ancestor::table
would be looking for a parent or ancestor element - ie up the HTML DOM. In contrast, #preceding_sibling
is looking for a sibling element - ie at the same level in the DOM (with the same parent).
You need to use #parent
instead:
element=@browser
.div(text: locator.strip)
.parent(tag_name: 'table')
.parent
.parent
.parent
.link(class: 'idit-grid-btn')
.i(class: "fa fa-#{var}")