Recommended way to locate parent element in Protractor

梦想的初衷 提交于 2019-12-23 06:57:29

问题


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?


回答1:


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 :)




回答2:


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();



来源:https://stackoverflow.com/questions/35237709/recommended-way-to-locate-parent-element-in-protractor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!