Finding a cascading element using watin

Please tell me how to search for a cascading element on a page.

For example, a page uses 10 anchor element tags. I can just get the element using the FindBy method, i.e. Element.FindBy (). But what to do when I have a cascading element in a css page, for example ".lineItem.title a"

+4
source share
1 answer

I'm not sure what you mean by cascading. Are you looking for the <a/> element contained in an element with class="lineItem" that is contained in an element with class="title" ? If so, at least two things you could do to find this element:

  • Use Find.ByExistenceOfRelatedElement<T>(ElementSelector<T> selector)

     ie.Link( Find.ByExistenceOfRelatedElement<Element>(link => link.Ancestor( Find.ByClass("title") && Find.ByExistenceOfRelatedElement<Element>(linksAncestor => linksAncestor.Ancestor( Find.ByClass("lineItem")))))); 
  • Use Predicate<Link>

     ie.Link(link => { var ancestor = link.Ancestor(Find.ByClass("title")); return ancestor != null && ancestor.Ancestor(Find.ByClass("lineItem")) != null; }); 

I bet there is another way.

+5
source

Source: https://habr.com/ru/post/1314915/


All Articles