Protractor Chained Elements by Using Variables?

前端 未结 3 661
半阙折子戏
半阙折子戏 2020-12-16 01:39

I am trying to keep my pageObjects in Protractor as clean as possible, but have run up against some behavior in selecting sub-elements.

This works:

v         


        
3条回答
  •  萌比男神i
    2020-12-16 01:58

    You could use the locator() function to get the locator of the child element and use it to find a child of the parent. This is similar to the solution you provided in your comment, but allows you to define all properties on your page object as web elements instead of a mix of elements and locators:

    var parent = element(by.css('.parent-class'));
    var child = element(by.css('.child-class'));
    
    parent.element(child.locator()).getText();
    

提交回复
热议问题