Reputation: 473873
According to the newly published Style Guide, using the by.xpath()
locators is considered a bad practice. I'm actually trying to follow the suggestion, but stuck on getting a parent element.
Currently we are using ..
XPath expression to get to the element's parent:
this.dashboard = element(by.linkText("Dashboard")).element(by.xpath(".."));
How can I locate the element's parent using other built into Protractor/WebDriverJS locators?
Upvotes: 15
Views: 11071
Reputation: 3731
While I dig the Style Guide, and agree that xpath is to be avoided, there's always an exception that proves the rule. I think this is one of those cases :)
Upvotes: 11
Reputation: 9988
Actually, at the moment there is an easier way to select the parent of an element avoiding to use xpath
.
From an ElementFinder
you can simply access the parent element through parentElementArrayFinder
and then for example trigger the click
method:
myElement.parentElementArrayFinder.click();
Upvotes: 6